in reply to Need help on part of homework

ah, I see the problem. 7 Eggs and 4 Milk gives:
Milk 11
Eggs 11

You want a quantity for each item type, not one total. The simple would be to create my %groceryquantities and use that instead of my $quantity.