open OUT,'|program' or die $!; open IN,'file.txt' or die $!; #if you don't need to process each line...I don't see why not printing all the lines at once like: print OUT ; #but if you must print one line at a time: while(){ #do whatever you want with the line. print OUT $_; } close OUT; close IN;