Perl: find the index of an array item

I needed to find the index of an item in an array so I wrote a simple Perl function.

sub array_id {
   my ($needle,@haystack) = @_;
   my $count = 0;

   foreach my $item (@haystack) {
      if ($item eq $needle) {
         return $count;


   return -1;

Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
Logged IP:
To prevent spam please submit by clicking the kitten: