in reply to detecting errors when a sub returns undef

Perhaps a silly question, but why not just omit keys with undefined values from the hash in the first place?

If you can't omit keys with undefined values, change your code to:

sub check_foo { if (exists $foo{bar} and $foo{bar}) return $foo{bar}; } else { return undef; } }