#!/usr/bin/perl use strict; use warnings; my $file = '/path/to/file'; open my $fh,'<',$file or die $!; while(my $line = <$fh>){ print sprintf("%4d %s",$.,$line); } close $fh;