in reply to printing Matrix
Try to replace sort keys %$A with @letters and see what happens. If you want to print a string with a given width you could try
printf "%4s ", $key; [download]