while (){ if (/$foo/){ $that = 1; } if (/$bar/){ last; # emergency exit from the loop ;-) } if ($that){ print $_; } } #### while (){ last if /$foo/; # ignore all lines until we find foo } while (){ last if /$bar/; print $_; # do something with the lines we find now } close FOO_FILE; # just ignore the rest of the file