in reply to Does Perl support a given number of replacements ?

Lots of good solutions here. If you can clearly isolate the thing you want to change, you can keep it pretty simple and control the number of changes with $i:
$x = 'ababababab'; $i=3; $x =~ s/(^|[^a])a([^a]|$)/$1B$2/ while $i--; print "$x\n" __END__ BbBbBbabab
--marmot

Replies are listed 'Best First'.
Re^2: Does Perl support a given number of replacements ?
by Anonymous Monk on Jun 08, 2009 at 04:31 UTC
    Hi again, Thank you all for your time and solutions, I see that the problem becomes trickier when it comes to RE's ..., but at least now I know how Perl handles this situation. Appreciate your help. Thanks.