sub validate_hostname{ my $candidate = shift; my ($ascii_only, $verbose, $debug) = @_; # leave room for improvments and flexibility my ($return, $descr); # non ASCII if ( $candidate =~ m/[^[:ascii:]]/ ) { # but see: https://perlmonks.org/?node_id=11164574 print "Not ACSII\n" if $verbose; # ..accepted? if ($ascii_only){ return wantarray ? (undef,"non ASCII string [$candidate] rejected") : undef; } # go with another specialized sub.. validate_hostname_Unicode($candidate,$ascii_only, $verbose, $debug ); } # ASCII # too long.. if (length $candidate >= 255){ $descr = "[$candidate] is too long (".length $candidate." chars)"; print $descr if $verbose; return wantarray ? (undef,$descr) : undef; } # Hostnames might be composed by 1 or more labels (separated by dots) unless ($candidate =~ /\./){ $descr = "[$candidate] contains no dots"; print $descr if $verbose; return wantarray ? (undef,$descr) : undef; } # .. more checks for this rule # Each label may have at most 63 characteres ... #..have fun :) }