$text = 'Cheese.Bacon'; $v1 = '(\w+)\.(\w+)'; $v2 = '$2\.$1'; $test =~ s/$v1/$v2/;