print "Enter a target value to search for:"; use List::MoreUtils; chomp (my $search = ); my $index = List::MoreUtils::first_index {$_ eq $search} @array; if ($search) { print "The last occurence of $search is at index: $index\n"; } else { print "Target is not found\n"; }