in reply to how do subroutines work

If you add print "@_\n"; between sub zivad { and my $animal = shift;, perl will tell you exactly what is in @_. In this case you'd see mago (which comes from print zivad('mago');).

%list can be accessed anywhere after my in the snippet you posted, and that's just what your subroutine is doing.

This is what happens step-by-step