use strict; use warnings; my %hash = ( sorter1 => { domain1 => [ 123, 124, 112, 110, ], }, ); foreach my $sorter (keys %hash) { print "\n\nSORTER=$sorter"; foreach my $domain (keys %{$hash{$sorter}}) { my $current = 0; my $show_max = 2; foreach my $time (reverse sort @{$hash{$sorter}{$domain}}) { print "\nDomain=$domain, Time=$time"; (++ $current >= $show_max) and last; } } }