in reply to This is Strange!!! Please help me..

The opening parenthesis "(" is special in regular expressions. See perlre. Most likely you want to use quotemeta before interpolating a string into a regular expression, or use \Q...\E like this:

if ($str =~ m/\Q$tr\E/) { ... };

For stylistic points, the /g on your regular expression serves no purpose.

To help us help you better, please do not vaguely rephrase Perl error messages but copy and paste the error messages.

Replies are listed 'Best First'.
Re^2: This is Strange!!! Please help me..
by ikegami (Patriarch) on Sep 28, 2010 at 14:29 UTC
    It's not just a stylistic problem.
    >perl -E"$x='a'; for (1..2) { if ($x =~ /a/g) { say 1 } else { say 0 } + }" 1 0