http://www.perlmonks.org?node_id=1035335


in reply to Find common values in a hash and print the respective keys

Reverse the hash into a HoA and select those with multiple values in the array.

$ perl -MData::Dumper -Mstrict -Mwarnings -E ' my %h = ( aa => 1, bb => 2, cc => 3, dd => 4, ee => 2, ff => 5, gg => 3, hh => 2, ); my %r; push @{ $r{ $h{ $_ } } }, $_ for keys %h; print Data::Dumper->Dumpxs( [ \ %r ], [ qw{ *r } ] ); say qq{Value $_ present in keys @{ [ join q{, }, @{ $r{ $_ } } ] } } f +or grep { @{ $r{ $_ } } > 1 } keys %r;' %r = ( '1' => [ 'aa' ], '4' => [ 'dd' ], '3' => [ 'gg', 'cc' ], '2' => [ 'bb', 'ee', 'hh' ], '5' => [ 'ff' ] ); Value 3 present in keys gg, cc Value 2 present in keys bb, ee, hh $

I hope this is helpful.

Cheers,

JohnGG