unless ($num =~ /^\d{5,}$/) { # and more generally to combine a couple of conditions: unless ($num =~ /^\d{5,}/ and $num !~ /\D/) {