use IO::Handle; use Fcntl; use POSIX qw(exit); $SIG{PIPE} = 'IGNORE'; my $handle = IO::Handle-> new; $handle-> autoflush(1); my $pid = open( $handle, '-|'); if ( $pid) { # parent # make it non-blocking my $fl = fcntl( $handle, F_GETFL, 0); die "$!" unless defined $fl; fcntl( $handle, F_SETFL, $fl|O_NONBLOCK) or die "$!"; # attach to your gui system so your callbacks are # pinged whenever something appears on $handle MyFictitiousGUI::FileListener->attach( $handle, on_read => sub { message( <$handle>); }, on_close => sub { message("it's over!") } ); } else { # child $|++; while ( do_computation) { print "$percents done\n"; } POSIX::_exit(0); }