for my $book_id (@sorted_books) { print "$book_id: ",join ", ",@{ $books{$book_id} }; print "\n"; }