I don't think you need to build a new array, and I think
any may be faster than
grep because it doesn't always traverse the whole array and it potentially uses the C implementation (
List::MoreUtils). I used $x instead of $a, which has
special super powers.
use warnings;
use strict;
use List::MoreUtils qw(any);
my %hoa = (
x => [ qw(a b c d) ],
y => [ qw(e f g) ],
z => [ qw(h i c j) ],
);
my $x = 'c';
for my $k (keys %hoa) {
print "key $k has $x\n" if any { $_ eq $x } @{ $hoa{$k} };
}
__END__
key x has c
key z has c