my (@common, @uniq1, @uniq2); for (keys %hash1) { if (exists $hash2{$_}) { push @common, $_; delete $hash2{$_}; # All that will be left in hash2 is what wasn't in hash1 } else { push @uniq1, $_ } } @uniq2 = keys %hash2;