in reply to How to pass two arrays to a sub?

You don't have two lists, you have two arrays. Arrays and lists are different. See the FAQ What is the difference between a list and array?

Your two arrays get flattened into a single list to be passed to the subroutine. Subroutines can only ever get one list of arguments. Inside your subroutine you try to assign the list into two array variables. But as list assignment is greedy, all of your list elements end up in @array1.

The solution to your problem is to pass two array references to your subroutine.

It's also worth noting that Perl subroutine prototypes are a bit of a double-edged sword. They don't really do what most people seem to expect them to do and therefore they are probably best avoided most of the time.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg