# untested FILE: for (glob '*.txt') { open my $fh, '<', $_ or die "$_: D'Oh! $!\n"; my $found; while (<$fh>) { /green|red|blue/ and $found++ if !$found; next FILE if /green red blue/; } print if $found; # $\ eq "\n" }