in reply to Regex match and replace

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";

Replies are listed 'Best First'.
Re^2: Regex match and replace
by Anonymous Monk on Mar 04, 2015 at 22:30 UTC

    That's pretty neat, thanks!