my @ref = qw(Red Green Yellow); my @data = qw(Yellow Black Yellow Red White Yellow); for my $search (@ref) { my @found; for my $index (0..$#data) { if ($data[$index] eq $search) { push @found, $index; } } print "$search: [@found]\n"; } #### Red: [3] Green: [] Yellow: [0 2 5]