my $new_value='$2 and $1'; my $string="(Jack) and (John)"; my $regex=qr/$string/; $string=~s/$regex/$new_value/;