Summary: How to use a Perl foreach loop to print every element in a Perl array.
To look at how to print every element in a Perl array using the foreach operator, the first thing we need is a sample array. Let's assume that you have an array that contains the name of baseball teams, like this:
@teams = ('cubs', 'reds', 'yankees', 'dodgers');
If you just want to print the array with the array members separated by blank spaces, you can just print the array like this: