my @in = qw(bga cbga test); my @out; my @test = qw(bga); foreach my $test (@test) { push @out, grep { $_ eq $test } @in; }