My approach was almost the same as yours except I used a function so I could short circuit and return as soon an item was determined to be missing.
use warnings;
use strict;
use Data::Dumper;
my @allwords = qw( mary had a little lamb its fleece was white as snow
+ );
my @checkwords = qw( little lamb fleece everywhere );
print "All words were ", check_array_for_words(\@allwords, \@checkword
+s) ? "" : "not ", "found.\n";
sub check_array_for_words {
my ($ar_allwords, $ar_checkwords) = @_;
my %hash;
foreach (@$ar_allwords){
$hash{$_} = undef;
}
print Dumper(\%hash);
foreach (@$ar_checkwords) {
if (not exists $hash{$_}) {
return 0;
}
}
return 1;
}
__END__
$VAR1 = {
'had' => undef,
'lamb' => undef,
'a' => undef,
'fleece' => undef,
'little' => undef,
'white' => undef,
'as' => undef,
'was' => undef,
'mary' => undef,
'snow' => undef,
'its' => undef
};
All words were not found.