in reply to array sorting

You can use either

print join(" ", sort @animals);

or

print "@{[sort @animals]}";

For an explanation, see Perl Idioms Explained - ${\$obj->method} and @{[sort @list]}