Assuming you are using Perl 5.10 and higher, you can use the // operator.
my $a = defined $x ? $x : $default;
Similarly, you can do
my $b = defined $hash{$_} ? $hash{$_} : $default;
Note that in my example above, I am checking for defined $hash{$_} , not exists $hash{$_} , like you do. There is no abbreviation for existence, nor for definition.
Finally, you have the //= operator, so you can do;
$a = $x unless defined $a;
This is similar to ||= , which does the same for truth:
$a = $x unless $x;
source share