my $match_re = qr{ ^ /:swiss \| \w+ \| \w+ }x; foreach my $line (@array_of_strings) { if($line =~ /$match_re/) { ... } }