if ($label eq "A"){ $fields[-2] = $a_vals[ $index ] } if ($label eq "B"){ $fields[-2] = $b_vals[ $index ]