my %allKeys; foreach my $i ( 0 .. $#data ){ my $hash = $data[$i]; for (keys %$hash) { push @{$allKeys{$_}}, $i; } } foreach my $key ( sort keys %allKeys ){ my $locations = $allKeys{$key}; printf "Key '%s' was seen %d times at these indices: %s\n", $key, scalar @$locations, join(", ", @$locations); }