The essence is that you are using regex to match - but what you want to do is use s/regex/replace/ to replace. Details on how to do it in your case has been covered extensively above.
In reply to Re: Replacing whitespaces with a regex
by tmharish
in thread Replacing whitespaces with a regex
by Dr Manhattan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |