use warnings; use strict; my %one = (a => 1, b => 2, c => 3); # first hash my %two = (a => 1, c => 3); # second hash for my $x (keys %two){ if (exists $one{$x}){ print "hash \$two key $x exists in hash \$one\n"; } }