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