if ( defined($x) && length($x) && $x !~ /\D/ && 0 <= $x && $x <= 10 ) { # It matches }