mikevh,
You're the best. Works like a champ. Don't suppose, purely for my edification, that you could explain the for loops that are printing the hash?
for my $k (sort keys %h)
{
print "$k\t";
for my $j (sort keys %{$h{$k}})
{
print "$h{$k}{$j}\t"...