use strict; use warnings; my $h = { ID1 => { myStr => 'hello', description => 'Description 1', yourStr => [ 'goodbye', 'where', 'hello'] }, ID2 => { myStr => 'good', description => 'Description 2', yourStr => [ 'hello', ] }, ID3 => { myStr => 'testvar', description => 'Description 2', yourStr => [ 'hello', 'good' ] }, }; my %yourstr; for my $id ( keys %$h ) { for ( @{ $h->{$id}->{yourStr} } ) { push @{ $yourstr{$_} }, $id; } } for my $id ( keys %$h ) { my $mystr = $h->{$id}->{myStr}; if ( $yourstr{$mystr} ) { my @matches = grep { $_ ne $id } @{ $yourstr{$mystr} }; print "'$mystr' in $id matches @matches\n"; } }