my @found_keys = grep { exists($hash_b{$_}) } keys %hash_a; my @matched_keys = grep { $hash_a{$_} eq $hash_b{$_} } @found_keys; if ( @found_keys == keys %hash_a ) { # All keys in %hash_a were found. } if ( @found_keys == keys %hash_b ) { # All keys in %hash_b were found. } if ( @found_keys == @matched_keys ) { # All keys matched values. }