I'd like to do something like this:
my $text = "The owls are not what they seem.";
my $pattern = '(\s+)';
my $replacement = '-$1-';
$text =~ s/$pattern/$replacement/g;
$text should then be: The- -owls- -are- -not- -what- -they- -seem.
But of course it's more like: The-$1-owls-$1-are-$1-not-$1-what-$1-they-$1-seem.
I tried all kinds of backreferences ($1, \1, \g{1}, \g1) and they all didn't work. The /e modifier didn't work either. Is this possible at all?
The purpose is to alter some text inside an object with a line like this: $object->replace('(.)oo', '$1ar')
Any other ideas how this could be done?
Thank you very much.