in reply to array sorting
You can use either
print join(" ", sort @animals); [download]
or
print "@{[sort @animals]}"; [download]
For an explanation, see Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}