in reply to Print last element using perl reference

at the same time print $#arr_ref is printing -1.

Of course. You never put anything in @arr_ref. Start by using use strict; use warnings;.

@array -> @$ref or @{$ref}
so
$#array -> $#$ref or $#{$ref}