require 5.013002; # or better: use Syntax::Construct qw(/r);
print "bla: ", $myvar =~ s/a/b/r, "\n";
See perl5132delta:
The substitution operator now supports a
/r
option that copies the input variable, carries out the substitution on the copy and returns the result. The original remains unmodified.
my $old = 'cat';
my $new = $old =~ s/cat/dog/r;
# $old is 'cat' and $new is 'dog'
来源:https://stackoverflow.com/questions/3440363/perl-use-s-replace-and-return-new-string#3440474
标签:old,string,cat,substitution,new,perl
From: https://www.cnblogs.com/profesor/p/18548408