use strict; use diagnostics; open my $fh, ") { $matches++ if /9432$/; last if $. == 100; # skip to end of while once we have reached line 100 # $. is a built-in variable, see perlvar in the docs }; close $fh; print "Found $matches matches.\n";