In Perl $#foo returns the index of the last element. To get the length you use @foo in scalar context. For eg:
my @bag_of_stuff = qw(do re me fa so la si);
say $#bag_of_stuff; # => 6
say scalar @bag_of_stuff; # => 7
NB. Lua arrays start at 1. Perl & most other languages start with 0 (zero) index