in reply to how to avoid using index of array

Maybe the point your teacher is trying to make is to investigate some of the Fine Modules on CPAN. E.g.:

>perl -wMstrict -le "my @rray1 = qw/boy boymonkey boydog/; my @rray2 = qw/girl girlmonkey girldog/; ;; use List::MoreUtils qw(pairwise); use vars qw($a $b); my @unions = pairwise { [ $a, $b ] } @rray1, @rray2; ;; use Data::Dumper; print Dumper \@unions; " $VAR1 = [ [ 'boy', 'girl' ], [ 'boymonkey', 'girlmonkey' ], [ 'boydog', 'girldog' ] ];

Update: Although if you're supposed to do it with a single for-loop and no indexing, maybe your teacher has something like this in mind (but this destroys the  @gals array):

>perl -wMstrict -le "my @guys = qw/boy boymonkey boydog/; my @gals = qw/girl girlmonkey girldog/; ;; my @unions; for my $guy (@guys) { push @unions, [ $guy, shift @gals ]; } ;; use Data::Dumper; print Dumper \@unions; " $VAR1 = [ [ 'boy', 'girl' ], [ 'boymonkey', 'girlmonkey' ], [ 'boydog', 'girldog' ] ];