in reply to Re: Find last position of an element in array
in thread Find last position of an element in array

You can avoid the maths with rindex:

$ perl -le ' my @arr = (1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4,4,5,5,6); print rindex( join (q{}, @arr), 4 ); ' 16

🦛