$num_cols = 5; @files = <*>; for (@files) { undef @bb; for ($i = 0; $i < $num_cols; $i++) { push @bb, shift @files; } push @data, [ @bb ]; }