if(exists {Keys of %line contains any values of $new{a} }) #need this condition #### if (grep { exists $line{$_} } @{$new{a}}) { #### #!/usr/bin/env perl -l use strict; use warnings; my @array = qw{a b c}; my %list = ( a => [qw{100 nuts}], b => [qw{200 bolts}], c => [qw{300 screws}], ); my $msg = getMsg(\@array, \%list); sub getMsg { my ($aref, $href) = @_; my %line = ( 100 => [qw{abc xyz}], nuts => [qw{def lmn}], ); for my $key (@$aref) { print 'Key: ', $key; if (grep { exists $line{$_} } @{$href->{$key}}) { print 'TRUE'; } else { print 'FALSE'; } } } #### Key: a TRUE Key: b FALSE Key: c FALSE