my %found_keys; for my $key (keys %hoa) { $found_keys{$key} = [grep { exists $hoa{$_} and $_ ne $key } @{$hoa{$key}}]; }