Hmmm
$input = "a b";
$input =~ s/\s/\\/g;
Tested and working, my test code
$abc = "a b";
$abc =~ s/\s/\\/g;
print $abc, "\n";
Cerberus:~ alexmac$ ./testaaa.pl
a\\\\\\\\\\b
This should work well for you. The idea is that we match \ s and will do it again and again until your corresponding character is like \ s, space character regular expressions
source
share