while (<>) { if (1 eq (/foo/ .. (1x0))) { do_something(); } } #### my $found; while (<>) { if (!$found && /foo/) { $found++; do_something() } }