#!/usr/bin/perl -w use strict; use 5.010; #for new //= operator use Data::Dump qw(pp); my @all_arrays = ([1 .. 20], [10 .. 30], [19 .. 40], ); my @unique_descriptive; foreach my $num (map{@$_}@all_arrays) { $unique_descriptive[$num]++; #simple peg counter } # add a column to the 2-D array with row number # undef counts as freq of zero, the //=0 does that my $i=0; @unique_descriptive = map{[$i++,$_//=0]}@unique_descriptive; @unique_descriptive = sort{ $a->[1] <=> $b->[1] #by freq or $a->[0] <=> $b->[0] #by peg number }@unique_descriptive; foreach my $row (@unique_descriptive) { print "num = $row->[0] \tfreq=$row->[1]\n" if ($row->[1] > 0); }