while ( ) { last if $_ eq 'foo'; # Where foo can only appear once in the file print; } while ( ) { print; }