# this is my sample function i cannot modify sub doIt() { print "blabla\n"; print STDOUT "blabla2\n"; #sample_app is a small script that writes some output to STDOUT and STDERR system("sample_app"); } sub execute() { pipe(RDR, WTR); my $pid = fork(); if ($pid == 0) { close STDOUT; open (STDOUT, '>&WTR'); select STDOUT; $| = 1; doIt(); print "child finished\n"; exit; } else { my $buf = ""; while ($buf !~ /child finished/) { $buf .= ; } sleep 2; print "parent got:\n$buf\n"; } } #### use threads; my $t = threads->new(\&execute); $t->join();