Black magic! I'm really impressed, I didn' know you
can put that all into the substitution pattern.
/me bows to Nuance ...
As for my solution, I was focused on the sample input
given, I didn't think of the more general problem.
But you're right about this.
As for your script, it works with a small alteration:
$string =~ s/($pattern)/$i++ == $n ? $better : $1/ge;
If you increment $i in a seperate statement, the
whole block evaluates to the value of $i und you get
abacab
0b1c2b
Ok, now we're having fun :-)...
Andreas (waiting for the chinese food delivery service ...)