sub alfNum { my ($aAlf, $aNum) = $a =~ /([a-z]+)(\d+)/i; my ($bAlf, $bNum) = $b =~ /([a-z]+)(\d+)/i; return $aAlf cmp $bAlf if $aAlf ne $bAlf; return $aNum <=> $bNum; } #### use strict; use warnings; use Data::Dump::Streamer; use strict; use warnings; my %hoh = ( A10 => {bl=>0, ff=>4, gg=>3}, A2 => {cc=>5, dd=>4, ee=>9}, A21 => {cd=>5, de=>4, ef=>9}, B21 => {og=>0, wo=>4, ee=>3}, B3 => {oa=>0, wd=>4, ec=>3}, B2 => {oo=>5, pp=>4, zz=>9}, ); my %alphaKeys; push @{$alphaKeys{(/^([a-z]+)/i)[0]}}, $_ for keys %hoh; keys %hoh; for (sort keys %alphaKeys) { my @lines; for my $key (sort alfNum @{$alphaKeys{$_}}) { my $index = 0; $lines[$index++] .= sprintf "%-20s", $key; my %items = %{$hoh{$key}}; $lines[$index++] .= sprintf "%-20s", "$_=>$items{$_}" for sort keys %items; } print "$_\n" for @lines; print "\n"; } sub alfNum { my ($aAlf, $aNum) = $a =~ /([a-z]+)(\d+)/i; my ($bAlf, $bNum) = $b =~ /([a-z]+)(\d+)/i; return $aAlf cmp $bAlf if $aAlf ne $bAlf; return $aNum <=> $bNum; } #### A2 A10 A21 cc=>5 bl=>0 cd=>5 dd=>4 ff=>4 de=>4 ee=>9 gg=>3 ef=>9 B2 B3 B21 oo=>5 ec=>3 ee=>3 pp=>4 oa=>0 og=>0 zz=>9 wd=>4 wo=>4