Without changing the original,how do we perform a replacement on a string using perl regex?
Method1:
(my $newstring = $oldstring) =~ s/foo/bar/g;
Method2:
my $newstring = $oldstring =~ s/foo/bar/gr;
Method3:
if it is an arrays:
my @a = ('appl', 'appl bal', 'fruit?');
my @b = map { s/appl/apple/; $_ } map { $_ } @a;
Labels: kaavannan perl blogspot, perl extract regex match, perl regex replace, perl regex substitution $1, perl replace line containing pattern, perl replace string in file command line, perl string replace