in reply to Find last position of an element in array

TMTOWTDI

$ perl -E ' my @array = (1,1,1,2,2,2,2,2,3,3,3,4,4,4,4,4,4,5,5,6); { local $" = ""; say rindex "@array", "4"; } say "@array[16, 17]"; ' 16 4 5

In your example data, you show only elements with single digits. The solution I presented assumes this is representative data.

— Ken