Skip navigation.
Your source for Perl tips, howto's, faq and tutorials
( categories: )


The general way of iteration is using foreach:

# print all elements of an array
foreach my $element ( @array )
  print $element . "\n";


If you want to iterate through an array to obtain a subset of its elements you may use grep:

# get all elements that begin with 'fun'
@fun_array = grep /^fun/ @array;

If you want to do something to each element of an array, you can use map:

# convert all elements to lowercase
@lowercase = map { lc } @array;