foreach my $key (@aminos) { print OUT $key,' '; foreach my $key2 (@aminos ) { printf OUT ("$forprint " , $A->{$key}->{$key2}); } } }