#!/usr/bin/perl use strict; open (PIPE,"| yourFile.txt") or die "Can't open pipe: $!"; select PIPE; $|=1; select STDOUT; my $count = 0; for (1..10) { print PIPE "line number $_\n" and $count++; sleep 1; } close PIPE or die "Can't close pipe: $!"; print "Wrote $count lines of text\n";