if ($condition) { $string =~ /(is a)/; $match = $1; } else { $string =~ /(regex)/; $match = $1; } print $match."\n";