open (IN, "$Path/$Sample_ID.Count.txt") or die; open my $SCR_chr1, '>>', "$Path/$Sample_ID.NewCount.txt" or die "Cannot create file for output: $!"; # go through the file line by line while (my $line = ) { # split the current line on tabs chomp ($line); chop($line) if ($line =~ m/\r$/); my @columns = split(/\t/, $line); print $SCR_chr1 "$columns[0]"; #Will print the Sample_ID in the #first column of the raw in new text file. for ($columns[0] =~ m/chr1$/) #if column[0] has specific Sample ID { #and uses the ~2500 tab-separated values in this raw for( my $i = 1; $i <= 250; $i++ ) { for( my $j; $j <= 10; $j++ ) ## I am hoping to parse first 10 columns (2-11) { ## But I dont know how to use the Next 10 columns (12-21) in next run of for loop. my $Column_Value += $columns[$j]; ## And add these value [first 10 columns (2-11)] to new variable } print $SCR_chr1 "\t$Column_Value "; ## and Print as new column in the file } print $SCR_chr1 "\n"; break; } }