http://www.perlmonks.org?node_id=918512


in reply to Getting indices of the same value that occurs multiple times in an array...

Here is what I would do (save you a loop).

my %og_to_gid; foreach (@COUNT) { my @a = split /\s+/; my $og = $a[0]; my $search_for = "1"; my @indices = grep { $a[$_] eq $search_for } 0..$#a; $og_to_gid{$og} = join ' ', map { $families[$_] } @indices; }