note
elusion
Well, let's go through this a step at a time. You want to search for 2 or more consecutive spaces. There are two ways to do that: <code>/ +/</code> and <code>/ {2,}/</code>. I normally use the first one, as that's what I think looks best.
<p>
Second, you want to make a substitution. Enter <code>$var =~ s/.../.../;</code>. Now we have this: <code>$foo =~ s/( +)//;</code>. We just need to come up with something to substitute in there.
<p>
Well, you want <code> </code> for each space, so we want it repeated for the length of the spaces: <code>" " x length $1</code>.
<p>
Now to add that to our regular expression. The trick is to use the /e and /g modifiers, which interpret the second half of the substitution as an expression and substitute globally. <code>$foo =~ s/( +)/" " x length $1/ge</code> And that's it! You're done!
<p>
Hope this helps,
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-21569">
<p><b><A HREF="/index.pl?node=elusion&lastnode_id=1072">elusion</a></b> <b>:</b> <b><A HREF="http://matt.diephouse.com">http://matt.diephouse.com</a></b>
</div></div>
363182
363182