perl s/this/that/r ==> "Bareword found where operator expected"

As ruakh wrote, /r is new in perl 5.14. However you can do this in previous versions of perl:

(my $foo = $bar) =~ s/this/that/;

There's no better solution, no (though I usually write it on one line, since the s/// is essentially serving as part of the initialization process:

my $foo = $bar; $foo =~ s/this/that/;

By the way, the reason for your error-message is almost certainly that you're running a version of Perl that doesn't support the /r flag. That flag was added quite recently, in Perl 5.14. You might find it easier to develop using the documentation for your own version; for example, http://perldoc.perl.org/5.12.4/perlop.html if you're on Perl 5.12.4.

Tags:

Perl

Bareword