my $domain; if ($str =~ /(\w+)\.com/) { $domain = $1; } else { # no match $domain = ''; }