in reply to pattern matching a limited number of times
Result: ABCxyABCxyABCxyABCxyABCxyabxyabxyabxyabxyabxyabxyabxyabxyabxyabxy$_ = 'abxy' x 15; for(my $i = 0; m/ab/g and $i++<5;) { substr($_, $-[0], $+[0]-$-[0]) = 'ABC'; } print;
That looks about right to me.
Update: See my follow-up in another subthread, that in general, you need to set pos() whenever you change the original string before continueing searching.
|
|---|