if (defined($foo_2)){ # do something with $foo_2 } elsif (defined(foo_1)){ # do something with $foo_1 } else { # take defalut action }