The foreach statement iterates through items in a list: The statement has the following format:
foreach $i (@some_list) { # $i takes on each list item value in turn statement(s); }
For example (foreach.pl):
@a = (1, 2, 3, 4, 5); foreach $i (reverse @a) { # reverse is a functiion that flips the list order print $i; }