my $areEqual=1; if(keys %hash == keys %hash1) { foreach my $key(keys %hash) { if(!exists $hash1{$key}) { $areEqual=0; last; } } }