You're being bitten by "autovivification". When you check to see if $hash{d}{value} exists, Perl will autovivify $hash{d} if it doesn't already exist.
Your best solution is to do if ($hash{d} and !$hash{d}{value}) { ... }.
Jeff japhy Pinyan,
P.L., P.M., P.O.D, X.S.:
Perl,
regex,
and perlhacker How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart