#!/usr/bin/perl use IPC::Open2; my $cmd = 'whatever'; # really, I have no idea what you are doing $pid = open2(\*CHLD_OUT, \*CHLD_IN, $cmd) or die "oops: $!\n"; while() { chomp; my $file = $_; # now do whatever with $file. open(I,'<', $file); while (my $line = ) { ... # do whatever with each line in the file } }