in reply to Compute previous lines data

while (defined($pre_ref_pos_b) && defined($pre_ref_pos_e) eq $ref_p +os_b && $ref_pos_e) {

Because the  eq operator has higher precedence than the  && operator you are comparing the return value of defined($pre_ref_pos_e), which is either true or false, alphabetically to the numerical value in $ref_pos_b.    That expression will only be true if defined($pre_ref_pos_e) is true and $ref_pos_b contains "1".