$start-> configure (-text => "Start", -command => [\&count]); MainLoop(); { my $handle; sub count { if ($handle) { # get rid of previous file-event amd -handle $handle->DESTROY; undef *README; } open(README, "./test3.pl |") or die "Can't run program: $!\n"; $handle = $text_box->fileevent( \*README, 'readable', sub { my $line = ; if($line =~ /aaa/) { close README; wait; # reap child } $text_box -> insert ("end", $line); } ); } }