Differences between m/PATTERN/ and /PATTERN/ in perl

Viewed 2712

Is there any technical difference between the following code segments in perl? They seem to behave identical

my $str = "A cat is red";

if($str =~ /cat/) {
    print "Matches\n";
}

vs

my $str = "A cat is red";

if($str =~ m/cat/) {
    print "Matches\n";
}

The difference in this code is the "m" on line 3. Why would someone omit or not omit the "m"?

2 Answers
Related