in reply to Printing the count for regex matches

First, I congratulate you! This idea of using match global in a list context is a great one!

I wasn't exactly sure what you wanted as there is some ambiguity in the spec. I interpreted the intent to be: number of the strings that matched anywhere (not total number of matches of those strings) and which ones were they? Code below can be tweaked to do different things.

A few points that you may find interesting is that
1.To read the entire file into a single Perl variable, no while{} loop is required, just undef the record separator and do a scalar assignment! BTW, you will often see @var=(),$var=() and this has same effect as =undef.
2. It is possible to increment a hash value that doesn't even exist yet! Perl will create it and set value =1 on the first increment.
3. You will see that I "cheated" in the print. The concatenation op like: "".keys(%seen) forces keys into a scalar context, scalar keys(%seen) would have been fine too, but this is just a fine point that you may find useful later, eg, print "blah".@array is different than print "blah", @array.
4. I took the /m out of the regex, you may need this if a string spans across \n boundaries.
5. You can expand this code to say print a table of number of times each string matched, etc.

#!/usr/bin/perl -w use strict; my %seen; $/=undef; #input record separator doesn't matter any more my $data = <DATA>; #whole file is read into one variable! my @match = ( $data =~ /(first_string|second_string|third_string|fourt +h_string|fifth_string)/g ); foreach (@match) { $seen{$_}++; #yes, you can increment a hash key that #doesn't exit yet! } #now we have a hash of strings that were seen. #also know the number times each string was seen. #but that doesn't appear to be necessary to know that here? print "".keys(%seen)," matches found: ", join(", ",sort keys(%seen))," +\n"; __DATA__ This is a test file matchme ljldjlfjd l;djfldjlf d test test test dljfldjlfjldjfldjlljdf one second_string dlfjldfj ljdfldjjf ldjfljdl dfljdlfj dfdlfj three ljfldjlj dlfjlasdj foiidufoiida matchdf dljfldsaofuoidfousdaof ladsjflasdof first_string dlfjodsuofuasdo sadoufosadu foasduf aosduf third_string __END__ __above prints: 3 matches found: first_string, second_string, third_string