in reply to How to match String with Case Sensitive??

If you want case sensitive matching, just remove the i at the end.

In any case your test will return true if $test1 is a substring of $test, and if it contains special regex syntax it's something else completely. So you could do

if ($test =~ m/^\Q$test1\E\z/) { ... }
instead to avoid that.
Perl 6 - links to (nearly) everything that is Perl 6.

Replies are listed 'Best First'.
Re^2: How to match String with Case Sensitive??
by Sachin (Acolyte) on Oct 30, 2009 at 12:14 UTC

    Thansk for Reply. I removed the i at the end. But it is not matching.

    #! /usr/bin/perl my $test = "abc"; my $test1 = <STDIN>; # Suppose test1 = "AbC" if($test =~ m#$test1#){ print "\n Both are Same"; } else{ print "\n Both are not Same"; }
      That's because the line terminator, "\n" is at the end of $test1.
      chomp($test1);

        I also tried with chomp($test1); and chop($test1); method. but it's not working..

        #! /usr/bin/perl my $test = "abc"; my $test1 = <STDIN>; # Suppose test1 = "AbC" print $test1; chop($test1); if($test =~ m#$test1#){ print "\n Both are Same"; } else{ print "\n Both are not Same"; }