tee('foo'); tee('bar'); tee('baz'); while (<>) { print } sub tee { my $key = shift; # reopen STDOUT in parent and return return if my $pid = open(STDOUT, "|-"); die "cannot fork: $!" unless defined $pid; $|++; # process STDIN in child while () { chomp; print "$key: <$_>" or die "tee output failed: $!"; } print "$$ exiting...\n"; exit; # don't let the child return to main! }