in reply to Compute previous lines data

how should I put in the program so that it will reset the count whenever the the ref_pos_b and ref_pos_e is different from the proceeding lines.

Just reset it if the current value isn't equal to the previous one, e.g.

if ($ref_pos_b eq $pre_ref_pos_b) { $count++; } else { $count = 1; # reset }