Perl foreach Loop
The Perl foreach loop is used to iterate over the values of a list or collection variable.
Syntax
The syntax format is as follows:
foreach var (list) {
...
}
Flowchart

Example
#!/usr/bin/perl
@list
=
(
2
,
12
,
36
,
42
,
51
)
;
Executing the foreach loop
foreach
$a
(
@list
)
{
"
The value of a is:
$a
\n
"
;
}
Running the above program, the output is:
a 的值为: 2
a 的值为: 12
a 的值为: 36
a 的值为: 42
a 的值为: 51
Perl Loops