http://www.perlmonks.org?node_id=72504


in reply to fixstyle script in PERL COOKBOOK

That is odd...
#!/usr/bin/perl $string = "a\@b.c\n"; $string =~ s#\Qa@b.c\E#email-address#g; print $string; $string2 = "a\@b.c\n"; $string2 =~ s#a\@b\.c#email-address#g; print $string2; $string3 = "a\@b.c\n"; $qm3 = quotemeta('a@b.c'); $string3 =~ s#$qm3#email-address#g; print $string3;
Output:
a@b.c email-address email-address
So it seems that method won't work correctly. Perhaps another Monk can enlighten.

Corion suggests that \Q$var\E should work as normal; perhaps change the line that reads:
$code .= "s{\\Q$in\\E}{$out}g"
to read:
$code .= "\$var=quotemeta q{$in}; s{\$var}{$out}g"
for all to be well with the world. And it appears to, as well.

Update:D'oh, messed up the replacement line,fixed
Update:Corion once again points out that the reason for this is because @b gets interpolated before \Q takes effect. I should have realized this was the case.