How can I use $ _ to store my string, and then use another scalar variable to store the replaced string so that I have both instances. Do we have a modifier to copy the default argument to another variable?
use warnings;
use strict;
$_ = "X is a good boy. X works daily and goes to school. X studies for 12 hours daily \n";
s/X/Sam/g;
print $_, "\n";
In the end, I want the original $ _ and the substituted string to be there as well.
Edit: I used
my $new = s/X/Sam/gr
But I get an error related to the assembly, and it does not solve the problem. I am using version 5.10.1
perl --version
This is perl, v5.10.1 (*) built for x86_64-linux-thread-multi
source
share