tr/// does not take character classes, only literal strings and character ranges.
You need to quote the search string in s/// ...
cat x.pl; echo ; perl x.pl use strict; use warnings; while ( my $line = <DATA> ) { my $old = $line; my @match = ( $line =~ m/ "( [^"]* )" /gx ) ; #" for my $str ( @match ) { ( my $replace = $str ) =~ tr/,/|/ ; # Search string quoted. $line =~ s/ \Q${str}\E /$replace/gx; } printf "ORIG: %s NEW: %s\n" , $old , $line; } __DATA__ ONE,"TWo,2",Three,Four,Five ONE,"$TWo,2",Three,Four,Five ONE,"$TWo2","Three,(3)",Four,Five ONE,"$TWo2","Three,(3",Four,Five ORIG: ONE,"TWo,2",Three,Four,Five NEW: ONE,"TWo|2",Three,Four,Five ORIG: ONE,"$TWo,2",Three,Four,Five NEW: ONE,"$TWo|2",Three,Four,Five ORIG: ONE,"$TWo2","Three,(3)",Four,Five NEW: ONE,"$TWo2","Three|(3)",Four,Five ORIG: ONE,"$TWo2","Three,(3",Four,Five NEW: ONE,"$TWo2","Three|(3",Four,Five
In reply to Re: Search & Replace doesn't work with string containing certain special characters
by Anonymous Monk
in thread Search & Replace doesn't work with string containing certain special characters
by mmbb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |