foreach( keys %invalid ) { undef @tmp; @tmp = split $invalid{$_}, /\t/; while( @tmp ) { next if $_ =~ m/$fields[$_]/; } }