select(STDERR);$|=1;select(STDOUT);$|=1; # autoflush $cmd = 'perl b.pl 2>&1 | tee -a logfile.txt'; system($cmd);