[0] -> 1 4 6 8 9 ... [1] -> 1 3 5 6 20 ... [2] -> 2 3 4 5 6 ... [3] -> 5 7 8 9 12 ... [4] -> 3 5 8 11 13... [5] -> 4 5 7 8 9 ... [6] -> 1 4 5 7 8 ... ... #### 1. 5 -> is shared between all four arrays ([1],[2], [5], [6]) 2. 4 -> is shared between 3 arrays ([2],[5], [6]) #### for (1,2,5,6){ foreach $ar (@{$D[$_]}){ $hash{$ar}++; } } # sort %hash #pick top two