http://www.perlmonks.org?node_id=1021654


in reply to Replacing whitespaces with a regex

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.