my $run_pid = open(RUN, "sub_script.pl $options 2>&1 |") or $sub_failed = 1; if (!$sub_failed) { $text .= "Entered if (!\$sub_failed) {\n"; while () { $text .= "Entered while ()\n"; chomp; $_ =~ s/^\s*//; $text .= "$_\n"; } close(RUN); if ($? != 0) { $sub_failed = 1; } } else { $text .= "Failed to open sub_script.pl\n";} print "$text";