in reply to Passing reference to subroutine
$# doesn't give you the length but the last index. scalar gives the length.
Did you try $#{$variable}?