In my text file : ID dataR1 dataR2 dataR3 ... 1 324 445 654 2 234 654 768.5 3 542.12 764 98.2 . . . #### for(my $i = 0; $i < $originalfilecount; $i++) { #read in the current file open CURINFILE, "<$files[$i]" or die "Error couldn't open file $files[$i]\n"; print "$files[$i]\n"; while() { chomp $_; my @columns = split('\t'); push(@ID, $columns[0]); push(@data1, $columns[1]); push(@data2, $columns[2]); push(@data3, $columns[3]); print "\nWriting output..."; mkdir "$pathname" or die "Error couldn't create new Directory"; open OUT1, ">$pathname/column.txt" or die "error couldn't open output file"; print OUT1 "$data[1]" } close OUT1 }