open my $fh, "test.txt" or die $!; while(<$fh>) { print "$.:$_"; } __END__ outputs: 1:First line 2:Second line 3:Third line 4:Fourth line