How does pattern matching work in Perl?
问题 I want to know how pattern matching works in Perl. My code is: my $var = "VP KDC T. 20, pgcet. 5, Ch. 415, Refs %50 Annos"; if($var =~ m/(.*)\,(.*)/sgi) { print "$1\n$2"; } I learnt that the first occurrence of comma should be matched. but here the last occurrence is being matched. The output I got is: VP KDC T. 20, pgcet. 5, Ch. 415 Refs %50 Annos Can someone please explain me how this matching works? 回答1: From docs: By default, a quantified subpattern is "greedy", that is, it will match as