while() { push @full_data , [split] while (); for $arr_ref1 (@full_data) { for $arr_ref2(@full_data) { print OUT1 "$$arr_ref1[0]\t$$arr_ref1[1]\t$$arr_ref1[2]\t\t"; #print first three columns of input data into textfile $firstend = $firstinput + 2; $start2 = $firstend + 1; $secondend = $firstend + $secondinput; for my $index1 (3..$firstend)#column 4 to end of group 1 column { $ratio1 = sprintf( "%.4f%s", $$arr_ref2[$index1]/$$arr_ref1[$index1],"\t"); print OUT1 "$ratio1"; #$variable1 .= "$ratio1"; #attempting to store values in $variable1 } for my $index2 ($start2..$secondend)#start of group 2 column to end) { $ratio2 = sprintf( "%.4f%s", $$arr_ref2[$index2]/$$arr_ref1[$index2],"\t"); print OUT1 "$ratio2"; #$variable2 .= "$ratio2"; #attempting to store values in $variable1 } print OUT1 "\n"; #print next line after one loop } # finish one loop of one ID }