while(my $header_line = ) { my @headers = split/\s+/, $header_line; push @full_data , [split /\s+/, $_] while (); for my $arr_ref1 (@full_data) { for my $arr_ref2(@full_data) { for my $index (3..$#headers) { my $ratio1 = $$arr_ref2[$index]/$$arr_ref1[$index]; # this is the part where 1 and 2 is outputted. my $ratio = sprintf("%.4f", $ratio1); print OUT1 "$$arr_ref2[0]\t$$arr_ref1[0]\t$$arr_ref2[1]\t$$arr_ref2[2]\t\t$ratio1\n"; } } } }