foreach $person (sort keys %book) { if ($books{person}) { print $person has $books{$person} items\n"; } }