From perlfaq4: How do I change the Nth occurrence of something?
For example:
$ perl -le' my $x = "ababababab"; print $x; my $count = 0; $x =~ s/a/ ++$count <= 3 ? "B" : "a" /eg; print $x; ' ababababab BbBbBbabab
In reply to Re: Does Perl support a given number of replacements ?
by jwkrahn
in thread Does Perl support a given number of replacements ?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |