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