use strict; use warnings; my @matches; while () { push @matches, $1 if /((?:first|second|third|fourth|fifth)_string)/; } print scalar @matches, " matches found: ", join(", ", @matches), "\n";