in reply to Re: How to match String with Case Sensitive??
in thread How to match String with Case Sensitive??

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"; }

Replies are listed 'Best First'.
Re^3: How to match String with Case Sensitive??
by Anonymous Monk on Oct 30, 2009 at 12:17 UTC
    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"; }

        Hey! You are trying to match a constant against a pattern got from an input string. Is that what you want? Then try what moritz suggested.

        If not, change to:

        if($test1 =~ m#$test#){

        But without i modifier, "abc" will never be the same as "AbC".

        Of course, to be "the same" instead of just "contains", use:

        if($test1 =~ m#^$test$#){

        or:

        if($test1 eq $test){