There are a number of things wrong with the above examples:
1. If you are using $_ you don't need to specify it.
2. You don't need to escape the space in the pattern.
3. You should be using the '+' flag for "one or more" after the space, it's more efficient.
4. You should be using the 'g' flag for "global", otherwise it will only remove the FIRST space.
5. What's wrong with using the whitespace pattern '\s'?
To remove just spaces (from $_) use:
To remove all whitespace (from $_) use:
Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.