No external loop, no reverse and nothing but "-" in the substitution part:
$d =~ s/(?!^|$)(?(?{ pos() % 2 })(?!))/-/g;
Update: Bug fix. I originally forgot to prevent "-" from being placed at the end.
In reply to Re^2: Another puzzled RegEx Problem.
by ikegami
in thread Another puzzled RegEx Problem.
by pysome
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |