foreach (@input2) { open (STDOUT, ">$outputfile"); print $_ if m#$criterion#; }