use warnings; use strict; my $file= "capture.txt"; my $command= "ls"; open ( FILE, ">$file") or die "Can't open $file, stopped"; open ( PIPE, "$command |") or die "Can't open pipe, stopped"; while () { print ; print FILE; }