in reply to How to ignore ampersand and pound signs?

Hmm... not sure if I understood your question, but hopefully this would help you out.
#!/usr/bin/perl use strict; my $a = qq{<IL.Check/>}; my $b = qq{<&#x221a;>}; print "Old word: $a\n"; $a =~ s/$a/$b/; print "New word: $a\n";

Replies are listed 'Best First'.
Re^2: How to ignore ampersand and pound signs?
by Melk (Initiate) on Nov 04, 2009 at 01:44 UTC

    Thank you!

    The double q (qq) worked!

    Sorry for the basic question, I'm just starting out with Perl. :-)

      Nonsense. The single quote you originally posted works just as well.
      my $s = q[<IL.Check/>]; my $r = q[<&#x221a;>]; print "Old word: $s\n"; $s =~ s/$s/$r/; print "New word: $s\n";

      There's no interpolation or escape sequences here. q vs qq is moot.

      The real problem is that you are using text as a regex pattern without first converting it to a regex pattern. ("#" is special under "x".) Use quotemeta or its alias \Q..\E:

      my $s = q[<IL.Check/>]; my $r = q[<&#x221a;>]; print "Old word: $s\n"; $s =~ s/\Q$s\E/$r/; print "New word: $s\n";