#!/usr/bin/perl -w use strict; my %seen; $/=undef; #input record separator doesn't matter any more my $data = ; #whole file is read into one variable! my @match = ( $data =~ /(first_string|second_string|third_string|fourth_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