use Symbol qw( gensym ); for $file (@files){ open( my $fh= gensym(), "perl part2.pl $file |" ); # Error checking omitted for simplicity }