@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}); }