#!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