Many time I’ve found myself needing to perform some form of handling / manipulation of filenames and paths in my perls scripts. So I’ve tweaked a regex I found to one that adds an escape ( ‘\’ ) before each special character (allowing either shell or regex to understand the result). I know it’s limited and will only really work for *nix based systems, however I find it quite useful…
s/([\s\/\&%'`\-\@{}~!#\(\)&_\^\+,\.=\[\]])/\\$1/g