foreach $line () #### #!/usr/local/bin/perl -w my @test_array=( 'Element1', 'Element2', 'Element3', 'Element4', 'Element5', ); foreach (@test_array) { print "\"$_\"\n"; do_something(); } print "\n"; foreach (@test_array) { print "\"$_\"\n"; } sub do_something { open(IN, "$0") || die("No file"); while () { # Do nothing, in the real software we would do something # with the content. } close(IN); }