foreach $type (keys $allanimals) { my $num_of_animals = $allanimals{$type}->count_collection(); # A method in Animal::Colelction foreach $animal ($allanimals{$type}->get_animals()) { ## Using methods defined by the Animal interface ## But implemented in the Animal::Llama, Animal::Camel, etc subclasses. my $name = $animal->get_name(); $animal->feed(); } }