foreach(@inputs) { #localize the file glob, so FILE is unique to # the inner loop. local *FILE; local *OUTFILE; #NEW $file = "$FindBin::Bin/../rxo/$_"; $outfile = "$FindBin::Bin/../blocks/$_"; open(*FILE, "$file") || die; open(*OUTFILE, "> $outfile") || die; #NEW: added a star #push the typeglobe to the end of the array $fh = \*FILE; $ofh = \*OUTFILE; $regex = <$fh>; push(@regex,$regex); push(@filehandles,$ofh); }