for (1..25) { warn "File Exists: $_.txt\n" and next if -f "$_.txt"; print 'My prompt message: '; chomp(my $input = ); open my $fh, '>', "$_.txt" or warn $! and next; open my $ph, '-|', $cmd, $input or warn $! and next; { local $_; while {<$ph>) { do_your_processing($_); print $fh $_ or die $!; } } }