#!/usr/bin/env perl use strict; use warnings; use autodie qw{:all}; my $tail_cmd = 'tail -f ./pm_test_file_to_tail'; my @tail_captures; print '*** Start reading from $tail_pipe at ', time, "\n"; my $tail_pid = open my $tail_pipe, '-|', $tail_cmd; { local $SIG{INT} = sub { kill INT => $tail_pid if kill 0 => $tail_pid; waitpid $tail_pid => 0; }; while (<$tail_pipe>) { push @tail_captures, $_; } } print '*** Stop reading from $tail_pipe at ', time, "\n"; # Possibly process data captured, e.g. for demo only $_ = uc for @tail_captures; print '*** Captured via $tail_pipe:', "\n"; print for @tail_captures;