in reply to Escape the special characters while substitution

It has nothing to do with the substitution. The interpolation occurs before the assignment is even performed. You'd get a strict error has you been using use strict; as you should.
$ perl -wle'use strict; my $str2 = "@cce$$ag@!n"; print $str2;' Global symbol "@cce" requires explicit package name at -e line 1. Global symbol "$ag" requires explicit package name at -e line 1. Execution of -e aborted due to compilation errors. $ perl -wle'use strict; my $str2 = "\@cce\$\$ag\@!n"; print $str2;' @cce$$ag@!n

Now that the variables contain what you want them to contain, you still need to convert $str1 and $abc1 into a regexp pattern. quotemeta can be used to do that.

my $str1_pat = quotemeta($str1); $str1 =~ s/$str1_pat/$str2/; - or - $str1 =~ s/\Q$str1\E/$str2/; # Same thing.

But the fact that s/// is used at all is very fishy. s/// should be needed to change a password!

Replies are listed 'Best First'.
Re^2: Escape the special characters while substitution
by MidLifeXis (Monsignor) on Apr 24, 2009 at 19:12 UTC

    The fact that the passwords are being stored at all, assuming that this is to authenticate a user, is fishy. If at all possible, do not store this type of information.

    If you (the OP, not ikegami) are just using this to authenticate someone coming into your system, create a "difficult" hash of the password, and store that. When the user tries to authenticate the next time, run the same hash function, and compare the results to your stored results.

    --MidLifeXis

    The tomes, scrolls etc are dusty because they reside in a dusty old house, not because they're unused. --hangon in this post

Re^2: Escape the special characters while substitution
by bichonfrise74 (Vicar) on Apr 24, 2009 at 19:45 UTC
    I never knew about the quotemeta function. This is awesome!