use strict; use warnings; my $cmd = 'ls nonexistent'; open( CMD, "$cmd 2>&1 |" ) or die "Could not execute $cmd: $!\n"; while ( ) { chomp; print "<< $_ >>\n"; } __END__ % perl 483558.pl << ls: nonexistent: No such file or directory >>