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.
In Section
Seekers of Perl Wisdom