in reply to Hash key intersection

Here are two techniques (from the Perl Cookbook) that might point you in the right direction.

use warnings; use strict; my %hash_a = ( one => 'a1', two => 'a2', three => 'a3', five => 'a5', ); my %hash_b = ( one => 'b1', two => 'b2', three => 'b3', four => 'b4', ); suba (); subb (); sub suba { my ( @common, @uncommon ) = ( (), () ); foreach ( keys %hash_a ) { push @common, $_ if exists $hash_b{$_}; push @uncommon, $_ if not exists $hash_b{$_}; } foreach ( keys %hash_b ) { push @uncommon, $_ if not exists $hash_a{$_}; } print "in both: @common\n not in both: @uncommon\n\n"; } sub subb { my @common = grep { exists $hash_b{$_} } keys %hash_a; my @uncommon = grep { not exists $hash_b{$_} } keys %hash_a; push @uncommon, (grep { not exists $hash_a{$_} } keys %hash_b); print "in both: @common\n not in both: @uncommon\n\n"; }

The output is:

in both: three one two
not in both: five four

in both: three one two
not in both: five four