use strict; use warnings; use Data::Dumper; my $ncols = 5; # or obtained from user my @bigfatarray = (); push @bigfatarray, [] for [1 .. $ncols]; while () { my @cols = split (/,/, $_); for my $i (0 .. $ncols - 1) { push @{$bigfatarray[$i]}, $cols[$i]; } } print Dumper (\@bigfatarray); exit; __DATA__ 1,2,3,4,5 a,b,c,d,e