in reply to What does $#variable mean?

In case it's slipped by in the answers above, $LENDERCOUNT does not get the count of elements in @SORTEDLENDERS. It gets the last index, which will be one less than the number of elements.

You may be looking at an off-by-one bug.

The correct way of getting the count of elements in an array is:

$LENDERCOUNT = @SORTEDLENDERS;