my $match = 0; # Need to run each to the end # so its safe to use again later. while (defined(my $key = each(%hash1))) { $match ||= exists $hash2{$k}; } if (!$match) { # No common ... }