in reply to Printing the count for regex matches

In this case, you want all of the DATA in one go rather than in six separate lines. To achieve this, it'd be easiest to simply localize the input record separator $/, see perlvar for details. Basically, asking for <DATA> in a while loop grabs one record at a time, in this case one line at a time. That's because the input record separator is newline by default. If you do a local $/, you're effectively removing record separations, and the whole DATA segment will be read in at one time.
#!/usr/bin/perl use strict; use warnings; while (<DATA>) { my $string_found = $_; my @match = ( $string_found =~ /(first_string|second_string|third_stri +ng|fourth_string|fifth_string)/gm ); print scalar @match," matches found: ",join ", ",@match, "\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
Produces this result:
3 matches found: second_string, first_string, third_string,