Try: #!/usr/bin/perl -w use strict; $_ = "ABabcde12345BAABabcde1234blahblah5BA"; print "is: ", $_ , "\n"; my $count = () = $_=~ /(AB.*?BA)/g; my @match = /(AB.*?BA)/g; print "match: ", join(", ", @match), "\n"; print "I matched $count times\n";
The trick is: $_ =~ /../ applies the pattern to the string and returns a list of the 2 matches (due to the parens inside the RE). The same thing as: The empty parens supply the "list context" to the match, and then the assignment to $count puts that list into scalar context, akin to: my @match = $_ =~ /(AB.*?BA)/g; my $count = @match; or: print "I matched ", scalar @match, " times\n"; Okay, I'm a little shakey on the fact that, the empty parens seem to accept the list of return values (anonymous list, akin to an anon. array [] ?) and then act like an array (as: my $count = ('ABabcde12345BA', 'ABabcde1234blahblah5BA'); differs from: my $count = @match; in that the former assigns the final element of the list to $count, the later assigns the # of elements) but that's the case and thats how the matchbox gets opened and counted. a Andy Bach, Sys. Mangler Internet: [EMAIL PROTECTED] VOICE: (608) 261-5738 FAX 264-5932 Call out Gouranga be happy!!! Gouranga Gouranga Gouranga .... That which brings the highest happiness!! _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs