[ Well - even though this thread has been mostly about Perl, 
  it's still being posted to comp.lang.misc, so I'll reply. ] 
That is exactly ( and ALL ) that is needed. 
The Python example I posted, used the fact that any object which
supports read/readline/readlines or write/writelines methods 
can be used in place of a (builtin) file-object. ( The Python 
equivalent of a Perl "handle object" ) 
It is quite easy to redirect the output of a Python program 
to it's calling function. 
In the version I posted, the inner function must run to 
completion before producing any output. This is because 
the redirection is being done by a wrapper function 
( redirect.tolines ) that captures the output and
returns it to the caller, and so the semantics are not quite
the same a unix pipes. 
Objects can be induced to do a lot of the things that co-routines
can do (see several versions of generators and defered evaluation
sequences that have been posted to comp.lang.python), but in this 
case, a real co-routine is necessary for 2 way communication 
without blocking, so that a read of data from the inner function,
causes it to run until it write some data out ( which causes the
outer calling function to resume. ) 
-- Steve Majewski       (804-982-0831)      <sdm7g@Virginia.EDU> --
-- UVA Department of Molecular Physiology and Biological Physics --
-- Box 449 Health Science Center        Charlottesville,VA 22908 --
   [ "Cognitive Science is where Philosophy goes when it dies ... 
	if it hasn't been good!" - Jerry Fodor  ]