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"; #### This example_1 could be another example_2 where the example_3 is the example_4 I wanted