if ($string =~ /^[A-Z0-9]*\z/) { # String only contains characters A-Z, 0-9. ... } else { # String contains a character other than A-Z, 0-9. ... }