example of a previous sort: foreach $sym (sort {$pid_PFAULT{$pid}{$b} <=> $pid_PFAULT{$pid}{$a}} (keys %{$pid_PFAULT{$pid}})) (and the above required I be inside a loop knowing the $pid value) #### # text report by remoteIP:port sub text_sock_report_byrip() { my $pid, my $avg, my $rip, my $type, my $cmd; for $rip (keys %sock_total) { print "Report on remote host: $rip\n"; for $pid (keys %{$sock_total{$rip}}) { printf("pid: %s\n",$pid); for $type (keys %{$sock_total{$rip}{$pid}}) { printf("\t%s, ",$type); printf("\tcnt: %8d, ",$sock_total{$rip}{$pid}{$type}{'cnt'}); $avg = $sock_total{$rip}{$pid}{$type}{'tot'} / $sock_total{$rip}{$pid}{$type}{'cnt'}; printf("\tavg: %12.6f, ",$avg); printf("\tmin: %12.6f, ",$sock_total{$rip}{$pid}{$type}{'min'}); printf("\tmax: %12.6f\n",$sock_total{$rip}{$pid}{$type}{'max'}); } } } } #### VAR1 = 'R=10.10.0.111:54998'; $VAR2 = { '12913' => { 'write' => { 'tot' => '2.3e-05', 'min' => '0.000023', 'max' => '0.000023', 'cnt' => 1 } } }; $VAR3 = 'R=10.10.1.110:57354'; $VAR4 = { '12913' => { 'read' => { 'tot' => '1.5e-05', ..... etc....