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 ) { ... }