in reply to Check array for several matches

See the core module List::Util, especially all.

use strict; use warnings; use List::Util 'all'; # see below for how to properly create your hash my %words = ( foo => 1, bar => 1, baz => 1, qux => 1, ); my @must_exist = ( 'bar', 'qux', ); my $all_found = all { exists $words{ $_ } } @must_exist; if ( $all_found ) { ... }

As for the code you have:

Hope this helps!

update: added comments on OP code, then example with all


The way forward always starts with a minimal test.