if (defined(my $foo = exists $hash{$key})) { # ... }