my @common = (); foreach (keys %hash1) { push(@common, $_) if exists $hash2{$_}; }