use IPC::Open3 qw( open3 ); my @tail_pids; END { for my $tail_pid (@tail_pids) { kill TERM => $tail_pid; waitpid($tail_pid, 0); } } sub start_tail { my ($mw, $file) = @_; my ($from_tail, $tail_err); push @tail_pids, open3(undef, $from_tail, $tail_err, qw( tail -1lf ), $file); $mw->fileevent($from_tail, 'readable' => [ \&input_from_tail, $mw, $file ]); $mw->fileevent($tail_err, 'readable' => [ \&sink, $mw, $file ]); }