for my $key (keys %{$hash->{$a}{$b}}) { unless (exists $hash2->{$d}{$e}{$key}) { die "Key $key not found in hash2"; } }