Could you try to put the checker within the loop?

Something like

.

.

$table_row .= row($formula_disp, $cat[1], "+" .$cat_v_orig, $an[1], "-". $an_v_orig);

}else{

$table_row .= row($formula_disp, ans_rule(15), ans_rule(15), ans_rule(15), ans_rule(15));

push(@answers, $cat[1], "+" .$cat_v_orig, $an[1], "-". $an_v_orig);

**ANS(std_cs_str_cmp($answers[$i]));**

}

}

I haven't tried that with your problem, If I get the chance I'll let you know if it works.