while (...) { open INFILE, '<', ...; my $buffer = do {local $/; }; next if $buffer =~ /CLEAR/; ... } continue { close INFILE; }