This reads like a classic
XY problem. Why do you want to remove these characters? There may be a simpler solution, like
quotemeta (if you're trying to safely interpolate user input into a regex) or parameterised queries (if you're trying to avoid SQL injections).