in reply to Find and Replace with special characters

# XXX this modifies the input @lines ! my ($from, $to) = ( '#<-(0N<-(s3T' => '*<-(0N<-(s3T' ); for (@lines) { s/\Q$from\E/$to/g; } my @newlines = @lines; # XXX this modifies the input @lines ! for (@lines) { s{\Q#<-(0N<-(s3T\E}{*<-(0N<-(s3T}g; } my @newlines = @lines; # don't modify @input, copy it my @newlines = @lines; for (@newlines) { s{\Q#<-(0N<-(s3T\E}{*<-(0N<-(s3T}g; } # or, work on a copied my($var) my @newlines; for (@lines) { my $str = $_; $str =~ s{\Q#<-(0N<-(s3T\E}{*<-(0N<-(s3T}g; push @newlines, $str; } # or, use non-destructive s///r my @newlines; for (@lines) { push @newlines, s{\Q#<-(0N<-(s3T\E}{*<-(0N<-(s3T}gr; } # and again, more concise using a map: my @newlines = map s{\Q#<-(0N<-(s3T\E}{*<-(0N<-(s3T}gr, @lines;