my @matrix; foreach my $line(@filecontents) { chomp $line; push @matrix, [ split /\s+/, $line ]; }