my @data; while (<>) { my @fields = split ' '; for my $row (0..$#fields) { push @{$data[$row]}, $fields[$row]; } }