in reply to Re^2: Incremental replacement by regex
in thread Incremental replacement by regex

The 'g' in my example removes the need for the loop. One slightly pedantic comment on your code, you use \s and you should remember that it matches all whitespace, including a new-line. So, for example:
my $t = "This example could be another example where the example is th +e example I wanted, for example\n";
removes the trailing "\n" and replaces it with a space, which is probably not what you want.