if ($domain =~ /([A-Z0-9]+[A-Z0-9-]+[A-Z0-9])/i) { # $1 contains what is in the first pair of parentheses print "$1 matched\n\n"; } else { print "$domain did not match\n\n"; }