Just for grins, I took a stab at performance profiling of several solutions. I took out the final print statements. And it could be that my transcription contains some errors. But here are the results that I got with 4 runs:
#!usr/bin/perl -w use strict; use Benchmark; timethese (1000000, { jwkrahn => q{ my @array = ( "x y.g z 123", "a b.f c 456", "d b.c w 321" ); my @include = ( "b", "q" ); my @keep = map { my $item = $_; my $key = ( split )[ 1 ]; map {$key =~ +/\Q$_/ ? $item : ()} @include } @array; }, AnomalousMonk => q{ my @array = ('x y.g z 123', 'a b.f c 456', 'd b.c w 321'); my @include = qw(b q); my ($include) = map qr{ \b [$_] \b }xms, join '', @include; my $second = qr{ \b [[:lower:]] \b }xms; my $element = qr{ $include \. $second }xms; my @keep = grep m{ $element }xms, @array; }, Marshall => q{ 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}); } }, desemondo => q{ @array = ("x y.g z 123", "a b.f c 456", "d b.c w 321"); @include = ("b","q"); my %testHash = map { $_,1} @include; foreach my $tmp (@array) { my @tokens = split /\s+/,$tmp; my ($test,$rubbish) = split /\./, $tokens[1]; push (@keep, $tmp) if (exists $testHash{$test}); } } } ); __END__ Benchmark: timing 1000000 iterations of AnomalousMonk, Marshall, desemondo, jwkrahn... AnomalousMonk: 27 wallclock secs (26.42 usr +0.16 sys = 26.58 CPU)@37625.10/s Marshall: 17 wallclock secs (17.38 usr + 0.00 sys = 17.38 CPU)@57553.96/s desemondo: 40 wallclock secs (40.94 usr + 0.11 sys = 41.05 CPU)@24362.32/s jwkrahn: 77 wallclock secs (76.48 usr + 0.00 sys = 76.48 CPU)@13074.63/s Benchmark: timing 1000000 iterations of AnomalousMonk, Marshall, desemondo, jwkrahn... AnomalousMonk: 27 wallclock secs (26.45 usr + 0.09 sys = 26.55 CPU)@37669.04/s Marshall: 18 wallclock secs (17.36 usr + 0.00 sys = 17.36 CPU)@57607.01/s desemondo: 44 wallclock secs (44.05 usr + 0.14 sys = 44.19 CPU)@ 22631.09/s jwkrahn: 97 wallclock secs (97.92 usr + 0.02 sys = 97.94 CPU)@10210.65/s Benchmark: timing 1000000 iterations of AnomalousMonk, Marshall, desemondo, jwkrahn... AnomalousMonk: 27 wallclock secs (26.75 usr + 0.11 sys = 26.86 CPU)@37230.08/s Marshall: 18 wallclock secs (17.64 usr + 0.00 sys = 17.64 CPU)@56689.34/s desemondo: 47 wallclock secs (48.14 usr + 0.09 sys = 48.23 CPU)@20732.26/s jwkrahn: 106 wallclock secs (104.81 usr + 0.00 sys = 104.81 CPU)@9540.80/s Benchmark: timing 1000000 iterations of AnomalousMonk, Marshall, desemondo, jwkrahn... AnomalousMonk: 28 wallclock secs (27.27 usr + 0.08 sys = 27.34 CPU)@36569.76/s Marshall: 21 wallclock secs (20.39 usr + 0.00 sys = 20.39 CPU)@49043.65/s desemondo: 55 wallclock secs (54.77 usr + 0.11 sys = 54.88 CPU)@18223.23/s jwkrahn: 114 wallclock secs (115.05 usr + 0.00 sys = 115.05 CPU)@8692.10/s

In reply to Re^2: filter an array with consecutive splits by Marshall
in thread filter an array with consecutive splits by coldy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.