in reply to Non-destructive string substitution

$ perl -we'$foo = "abcdefghij"; ($bar) = grep s/[ei]/x/g, "$foo"; prin +t $bar' abcdxfghxj
(If I ever get my act together, I hope to implement $bar = $foo =~ s/[ei]/x/gr, but that will modify $foo as well as returning it as $bar.)

Replies are listed 'Best First'.
Re^2: Non-destructive string substitution
by Anonymous Monk on Dec 08, 2017 at 09:09 UTC

    this thread is old, I know, but I did the test and $foo is not modified, here the code i wrote

    my $s = "hi, how are you?"; my $s2 = ($s =~ s/,.*//gr); print "$s2 \n$s\n";
    __OUTPUT__ hi hi, how are you?
    hop this helps :)