print for map{ substr( $_, 1+index( $_, '|' ) ) } sort map { my $key1 = $_; map { pack 'NA* NA* A1 A*', split( '\.', $key1 ), split( '\.', $_ ), '|', $hash{ $key1 }{ $_ } } keys %{ $hash{ $_ } }; } keys %hash;