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