in reply to Re^2: problem with perl 5
in thread problem with regex in perl script intended for 5.20,but while running on 5.10

If you want to have the result in a second string you have to copy the input first.

my $output = $input; $output = s/\Q$oldstring\E/$newstring/gs;

Replies are listed 'Best First'.
Re^4: problem with perl 5
by Anonymous Monk on Mar 09, 2015 at 09:50 UTC

    Not quite, that second = should be a =~, and the shorter (more idiomatic, I'd say) way to write that is:

    (my $output = $string) =~ s/\Q$oldstring\E/$newstring/gs;