If you declare your iterator outside the loop, any value it had then will be restored afterwards.
#!/usr/bin/perl
use warnings;
use strict;
my @array = (1, 3, 5, 7, 9);
my $i="Hello there";
foreach $i (@array) {
print "This element: $i\n";
}
print "All done: $i\n";
Related examples in the same category