# m// in list context, no g flag if (my @match = $str =~ m/(pattern1)(pattern2)/i) { $str = function($match[0]); $var1 = function($match[1]); }