my @array; while ( my $line = ) { chomp; push @array, $line; } for( my $idx = 0; $idx <= $#array; $idx++ ) { my $line_no = $idx + 1; print "Line $line_no = $array[$idx]\n"; } __DATA__ Here's the first line Here's the second line Here is the third line Here is the forth line