in reply to How do I sort a hash in a hash?

If I'm understanding you correctly, adding sort when retrieving the keys of the inner hash like you do in the outer hash should do what you desire:

sub printIndex { for my $book ( sort keys %ibIndex ) { # notice the use of sort in the next line for my $keyword ( sort keys( %{ $ibIndex{ $book } } ) { my $pages = join( ', ', @{ $ibIndex{ $book }->{ $keyword } + } ); } } }