# $q contains the string to test my $quad = '([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'; given ($q) { when ( # Is it an IP? # matches 127 or 127. or 127.0 or 127.0. or... # does not match any quad above 255, or 127.0.0.1. # as the fifth dot fails the match /^((${quad}\.){0,2}${quad}\.?|(${quad}\.){3}${quad})$/ ) { $type = 'ip'; } ## end when ( ...) when (/\w+\.\w+/) { # Is it a domain name? # words.words $type = 'url' } default { $type = 'name' } # it must be a name then... } ## end given