Hope this helps.
use strict;
use warnings;
my @A1 = qw'A B C D E F';
my @A2 = qw'E F G H I J';
my @A3 = qw'Q W E R T Y';
my @A4 = qw'P O L I U G';
my @matrix;
$matrix[0][4] = [ $A1[3], $A2[3] ];
# Use one of the following
for(
my $i=0;
$i<@A1 || $i<@A2 || $i<@A3 || $i<@A4;
$i++
){
$matrix[0][$i+1] = [ $A1[$i], $A2[$i] ];
$matrix[1][$i+1] = [ $A3[$i], $A4[$i] ];
}
# OR
for(
my $i=0;
$i<@A1 || $i<@A2 || $i<@A3 || $i<@A4;
$i++
){
push @{ $matrix[0] }, [ $A1[$i], $A2[$i] ];
push @{ $matrix[1] }, [ $A3[$i], $A4[$i] ];
}
# OR
{
my $i = 1;
for my $elem (@A1){
push @{ $matrix[0][$i++] }, $elem;
}
$i = 1;
for my $elem (@A2){
push @{ $matrix[0][$i++] }, $elem;
}
$i = 1;
for my $elem (@A3){
push @{ $matrix[1][$i++] }, $elem;
}
$i = 1;
for my $elem (@A4){
push @{ $matrix[1][$i++] }, $elem;
}
}
# notice how $i is out of scope here
To print it out you could use Data::Dumper or YAML
use 5.010;
use Data::Dumper;
$Data::Dumper::Terse = 1;
$Data::Dumper::Indent = 1;
say Dumper \@matrix;
use YAML;
say Dump \@matrix;
use Data::Dump 'dump';
say dump \@matrix;
Data::Dumper
[
[
[
'A',
'E'
],
[
'B',
'F'
],
[
'C',
'G'
],
[
'D',
'H'
],
[
'E',
'I'
],
[
'F',
'J'
]
],
[
[
'Q',
'P'
],
[
'W',
'O'
],
[
'E',
'L'
],
[
'R',
'I'
],
[
'T',
'U'
],
[
'Y',
'G'
]
]
]
YAML
---
-
-
- A
- E
-
- B
- F
-
- C
- G
-
- D
- H
-
- E
- I
-
- F
- J
-
-
- Q
- P
-
- W
- O
-
- E
- L
-
- R
- I
-
- T
- U
-
- Y
- G
Data::Dump
[
[
["A", "E"],
["B", "F"],
["C", "G"],
["D", "H"],
["E", "I"],
["F", "J"],
],
[
["Q", "P"],
["W", "O"],
["E", "L"],
["R", "I"],
["T", "U"],
["Y", "G"],
],
]