You have three options:
This is not recommended, because the code is confusing.
$x = scalar (@array); # $x now contains the number of elements in @array.
@fruits = ("apple", "orange", "banana", "melon"); $a = $#fruits; # $a is now 3; $b = $#fruits + 1; # $b is now 4, i.e. # the no. of elements in @fruits.