Data::Dumper is adding the extra backslash:
$ perl -le' use warnings; use strict; use Data::Dumper; my $s = q{<img src="http://www.blah.com?one=[KEY]&two=[KEY]"/>}; print $s; my $value = q{13.95}; print $value; my $q_key = quotemeta( q{[KEY]} ); print $q_key; my $q_value = quotemeta( $value ); print $q_value; $s =~ s/$q_key/$q_value/g; print $s; print Data::Dumper->Dump( [ $s ], [ qw/s/ ] ); ' <img src="http://www.blah.com?one=[KEY]&two=[KEY]"/> 13.95 \[KEY\] 13\.95 <img src="http://www.blah.com?one=13\.95&two=13\.95"/> $s = '<img src="http://www.blah.com?one=13\\.95&two=13\\.95"/>';
And as others have said, you don't need to quotemeta the string half of the substitution operator.
In reply to Re: variables within substitutions?
by jwkrahn
in thread variables within substitutions?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |