in reply to filter an array with consecutive splits

Perhaps?
#!usr/bin/perl -w use strict; my @array = ("x y.g z 123", "a b.f c 456", "d b.c w 321"); my @include = ("b","q"); my %include = map { $_ => 1 } @include; my @keep; foreach my $row (@array) { my $important_letter = ($row =~ m/\s+([a-z])\./)[0]; push (@keep, $row) if ($include{$important_letter}); } foreach (@keep) { print "keep: $_\n"; } __END__ keep: a b.f c 456 keep: d b.c w 321
I would keep things simple. You need some kind of looping statement. Then something to figure out whether this is a "good" row or not? Normally regex is faster than split. I used a slice to avoid $1. Then there is an "if" and a push if this row is "ok". The regex can become fancier if need be, or sometimes less fancy is ok too...($row =~ m/\s+(\w)\./)[0];