use warnings; use strict; use IPC::Run qw/ run new_chunker /; my @cmd = ('yourcommand', 'arg1', 'arg2'); my (@out,@err); run \@cmd, '>', new_chunker("\n"), sub { my $line = shift; print $line; push @out, $line; }, '2>', new_chunker("\n"), sub { my $line = shift; print STDERR $line; push @err, $line; } or die $?;