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