I am guessing that
$x_ref and
$y_ref are array references and you are looking at the length of the string that represents the reference, eg
ARRAY(0x132a5fd). Perhaps you need to look at
scalar @$x_ref and
scalar @$y_ref to compare the number of elements.
Just a guess.
Cheers,
JohnGG
Update: Corrected rubber-fingered typo.