#!/bin/perl -w use strict; set_filter(); # sets the post-processing filter print "main processing is here\n"; print "and continues here\n"; exit; BEGIN { my $i=1; sub set_filter { return if my $pid= open( STDOUT, "|-"); # magic open die "cannot fork: $!" unless defined $pid; while( ) { printf "line %03d: %s", $i++, $_; } exit; } }