my @cols; for my $row (@array) { my @f = split /,/, $row; $f[2] = $b[$f[2]]; push @{$cols[$_]}, $f[$_] for 0 .. $#f; }