use strict; use warnings; my $cmd_1 = "perl hello.pl"; open (CMD, "$cmd_1 2>&1|") or warn ("!!! Can't run program: $!\n"); while (my $line = ) { print $line; #if ($line =~ m/^xyz/) #{ # # do some string manipulation and write it to another file #} } close CMD;