my $found; while (<>) { if (!$found && /foo/) { $found++; do_something() } }