use strict; use warnings; my $infile = 'whatever'; open my $fh, '<', $infile or die "Couldn't open '$infile' for read: $!\n"; while ( my $line = <$fh> ) { print "$.\n" if $line =~ m/^1$/; }