title: How to substitute sequential spaces individually in perl
body: <p>I want to replace every space in "a&nbsp;&nbsp;&nbsp;b" with "\&nbsp;" and the expected output is "a\&nbsp;\&nbsp;\&nbsp;b". <br/>
  I have tried the following code but the output did not satisfy.</p>
  
  <pre><code>#!usr/bin/perl -w
  use CGI;
  my $q = CGI -&gt; new;
  print $q -&gt; header();
  $input = "a   b";
  (my $output = $input) =~ s/\ /\\ /;
  </code></pre>
  
  <p>the output is "a\&nbsp;&nbsp;&nbsp;b" but not "a\&nbsp;\&nbsp;\&nbsp;b".<br/>
  How can I get it right?</p>