use strict; use warnings; my $str = "This example could be another example where the example is the example I wanted"; my $i = 0; $str =~ s/example/'example_'.++$i/eg; print "$str\n";