$error=1 if ($hostname =~/\.$/); #trailing . is bad my @labels = split(/\./, $good_string); foreach my $foo (@labels) { $error=1 if ($foo=~/^\-/); #can't start with a - $error=1 if ($foo=~/\-$/); #can't end with a - $error=1 if ($foo=~/^\d+$/); #can't be only numeric last if $error; } if ($error) { print "A hostname!\n"; } else { print "Not a hostname!\n"; }