my @a = ( 'a1', 'b2', 'c3', 'd4' ); my @b = ( '3', '4', '5', '6' ); my @results; foreach my $num (@b) { push @results, grep { /$num/ } @a; } # @results will contain 'c3' and 'd4'