my $regex = join '|', qw( red green blue ); foreach my $line ( @lines ) { next if $line !~ $regex; }