for my $fieldnum (0 .. $#fields) { if ( exists $hash{ $fields[$fieldnum] } ) { print $fh "$row\n"; next; } }