in reply to I've read perlref

You can easily return multiple values from a subroutine - it must be some weird other language you're thinking about, like C or Pascal, that can only return one value and not a list from a subroutine.

You can also pass in lists to a subroutine, but Perl automatically flattens all lists into one big list, and you lose the information which element came from one list:

use strict; sub foo { my (@args) = @_; print "$_\n" for @args; }; my @a = qw(a1 a2 a3); my @b = qw(b1 b2 b3 b4 b5); foo(1,2,3,4,5,@a,@b);

If you want to keep the distinction between the arrays, it is customary to pass the arrays via reference :

use strict; sub foo { my ($val1,$val2,$arr_ref1,$arr_ref2) = @_; print "$_\n" for ($val1,$val2,$arr_ref1,$arr_ref2); }; my @a = qw(a1 a2 a3); my @b = qw(b1 b2 b3 b4 b5); foo(1,2,\@a,\@b);

To get at the values in @a and @b, you'll need to dereference $arr_ref1 and $arr_ref2:

use strict; sub foo { my ($val1,$val2,$arr_ref1,$arr_ref2) = @_; print "$_\n" for ($val1,$val2); for my $array ($arr_ref1,$arr_ref2) { for my $element (@$array) { print "array: $element\n"; }; }; }; my @a = qw(a1 a2 a3); my @b = qw(b1 b2 b3 b4 b5); foo(1,2,\@a,\@b);

See also tyes References quick reference for a much more and better explanation.