if ( ref($data->{bar}) eq "HASH" ) { ... } # ok, even if $data->{bar} is empty/undef