in reply to Replacing string with []

c:\@Work\Perl\monks>perl -wMstrict -le "my $a = 'A_D1[1]'; ;; my $str = '123 A_D1 XYZ A_D1[1] BLAH A_D1[1] BLAH'; print qq{str = '$str'}; ;; $str =~ s{ \b \Q$a\E [ ] }{-}xmsg; print qq{str = '$str'}; " str = '123 A_D1 XYZ A_D1[1] BLAH A_D1[1] BLAH' str = '123 A_D1 XYZ -BLAH -BLAH'
(Note that I used a '-' (dash) as the replacement character just to make the example more clear.) (Update: See discussion of  \Q \E and friends in Quote and Quote-like Operators section of perlop. See also quotemeta.)


Give a man a fish:  <%-{-{-{-<