$ perl -e'$x="1 2 3 4 5 5 5 5 5 5"; $counts[$_]++ for $x=~/(\d)/g; print "$_ $counts[$_]\n" foreach (0..$#counts)' 0 1 1 2 1 3 1 4 1 5 6