select STDERR; $| = 1; select STDOUT; $| = 1; open(CMD, 'perl b.pl 2>&1|') or die $!; open(LOGFILE, '>', 'b.log') or die $!; my $input; while(sysread(CMD, $input, 1024)) { print $input; print LOGFILE $input; } close(CMD);