$VAR1 = [ [ undef, undef, undef, undef, undef, [ '10', '10', '10', '10', 0, 0, 0, 0, 0, 0, 0, 0, 0, ... #### my $msm = 1; foreach my $msmtable (@array1){ open (OUT,">","$ARGV[1].$msm.msm.dat") || die "$!"; for (my $x = 0;$x <$max[0];$x++){ foreach my $row (@{$array1[$msmtable]}){ print OUT "$array1[$msmtable][$row][$x],"; } print OUT "\n"; } $msm++; close OUT; } #### print OUT "$array1[$msmtable][$row][$x],";