my (%foo, %bar); # Populate %foo and %bar # Keys present in only one hash my @only_in_foo = grep { ! exists $bar{$_} } keys %foo; my @only_in_bar = grep { ! exists $foo{$_} } keys %bar; # Matching keys which have differences in values my @kv_different = map { if (exists $bar{$_} && $bar{$_} ne $foo{$_}) { $_ } else { () } } keys %foo; # Matching keys and values my @kv_equal = map { if (exists $bar{$_} && $bar{$_} eq $foo{$_}) { $_ } else { () } } keys %foo;