#!/usr/bin/perl use strict; use warnings; while () { my $string_found = $_; my @match = ( $string_found =~ /(first_string|second_string|third_string|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 __Current results__ 0 matches found: 1 matches found: second_string, 0 matches found: 0 matches found: 1 matches found: first_string, 1 matches found: third_string, __Wanted results__ 3 matches found: second_string, first_string, third_string