#!/usr/bin/perl use Data::Dumper; $array[0] = "sponge"; for ($_=2;$_<=20;$_+=2) { $num = $freq{$array[0]}{"freq"}++; $freq{$array[0]}{"value"}[$num] = $_; } $array[0] = "wombat"; for (1..5) { $num = $freq{$array[0]}{"freq"}++; $freq{$array[0]}{"value"}[$num] = $_; } my @sorted_array = sort {$freq{$b}{"freq"} <=> $freq{$a}{"freq"}} keys %freq; print Dumper(\%freq); print "@sorted_array\n";