Access Near the End of an Array
For an array @a we can use $#a for the index of the last element. We can also use -1. Also, -2 can be used to reference the second to last element, etc.
@lucky = (1,2,3,4,5,6,7,8);
print "The last 2 numbers ",
"are $lucky[-2] and #lucky[$#a].\n";
The last 2 numbers are 7 and 8.