http://www.perlmonks.org?node_id=26403


in reply to How do I find the Nth occurrence of a pattern?

Here is my monkified version of the nth_iter subroutine. You gotta love map{}.
#!/usr/bin/perl -w my @string = (34, 56, 78, 90, 98, 76, 54, 32, 10, 12, 13, 16, 19, 20, +10, 56); sub nth_iter{ my ($item, $n, $list) = @_; ( map { $string[$_] == $item ? $_ : (); } 0..$#string )[--$n] or -1; } print nth_iter(78, 1, \@string);