if ($var && $var !~ /\D/) { # We have a value and it's a number }