#!/usr/bin/perl use strict; sub screwed { my ($in) = @_; open(IN, "<$in"); while() { print "file $in contains $_"; } close(IN); } my @instances = ("a", "b"); map { print "before $_\n" } @instances; map { screwed "$_"; } @instances; map { print "after $_\n" } @instances; #### a1 a2 #### b1 b2 #### before a before b file a contains a1 file a contains a2 file b contains b1 file b contains b2 after after #### before a before b opening file named a opening file named b after a after b