my @arr = ( 110..117) ; # Generic array Iterator --- # Calls back $cb passing it a 2-element array : the INDEX, and an alias to the contents at that index sub iter{ my ($cb,$aref)=@_; # $cb is the callback sub ref passed in.. my $idx=0; for(@$aref){ $cb->($idx,$_); $idx++ } }; # Call the iterator iter(sub{print "ops : @_\n"},\@arr); # Prints: #ops : 0 110 #ops : 1 111 #ops : 2 112 # ....etc ...