my $sum = 0; while ( <>) { $sum++; last if m/perl/; } print "There were $sum lines until I found perl\n";