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