my $match = '(some [very] odd value).'; my $replace = '(modified value)'; # escape anything that might be a potential problem. # note -- we ignore known good values, rather than # encoding known bad values (so if we don't know about, # it gets encoded) $match =~ s/([^\w\s])/\\\1/g; my $regex = qr/$match/; my $SomeStuff = 'This is a test string (value); (some [very] odd value).'; $SomeStuff =~ s/$regex/$replace/g; print $SomeStuff;