my @items = map {$licensehash{$_->[0]}{$_->[1]}} sort {$a->[2] cmp $b->[2]} map { my $top = $_; map {[$top, $_, $licensehash{$top}{$_}[3]]} keys %{$licensehash{$_}} } keys %licensehash; print "$_->[3]: $_->[0]\n" for @items;