in reply to This is Strange!!! Please help me..
What is "if (/.../g)" suppose to mean, "check if it matches, then search the rest of the string to see if it matches too"? It makes no sense, and it will also cause hard to debug errors. Get rid of that "g".
"(" and ")" have special meaning in regex patterns. If you want to match a string literally, you'll need to convert the string you want to the match into a pattern that matches that string. quotemeta does that.
my $tr_pat = quotemeta($tr); if ($str =~ /$tr_pat/) {
or
if ($str =~ /\Q$tr\E/) {
or
if ($str =~ /\Q$tr) {
|
|---|