my @sorted_keys = sort { $hoa{$a}->[0] cmp $hoa{$b}->[0] } keys %hoa; foreach my $row_key ( @sorted_keys ) { print "$row_key:\n"; my $index = 0; foreach my $cell ( @{ $hoa{$row_key} } ) { print "$index = $cell"; $index++; } print "\n"; }