open my $cmd, "-|", qw(ls -al) or die $!; open my $file, ">", "filename" or die $!; while(<$cmd>) { print $file $_ }