my %isvalid; # outside of the loop over lines, of course! @isvalid{@validbufs}=(1) x @validbufs; #### print $line if $isvalid{$field};