You could also literally count the number of matches and only start replacing from the second match onwards:
use strict; use warnings; my $s="foofoo"; my $ctr = 0; $s =~ s/(foo)/$ctr++?"bar":$1/ge; print "$s\n";
In reply to Re: Regex match and replace
by hdb
in thread Regex match and replace
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |