use strict; use warnings; use autodie; my $filename = 'Text2.txt'; my $count = 0; open my $file,'<',$filename; while (my $line = <$file>) { ++$count; # keep track of the number of lines printf "Line $count: $line"; } close $file; exit 0; #### use strict; use warnings; use autodie; my $filename = 'Text2.txt'; my $count = 0; my @lines; # declare the array to be used for storing open my $file,'<',$filename; while (my $line = <$file>) { ++$count; # keep track of the number of lines push (@lines,'Line ',$count,': ',$line); # fill the initially empty array with the needed data } close $file; # do not need this anymore for my $newline (@lines) { printf $newline; # print the contents of the filled array } exit 0;