if $str =~ /\D/ { print "non-digit" } #### if $str !~ /^\d\d$/ { print "wrong length or contains non-digits" }