in reply to Tacking a function on to STDOUT?

You should be using Filter::Handle, no doubt. But if you want to do it yourself (say as a quick and dirty hack), it's actually fairly easy. The perldoc perltie manpage has the details.

Of course, you're still probably best off dividing it into 2 parts, a file containing the module IO::SubHandle: (properly located) and the main program.

#!/usr/local/bin/perl -w package IO::SubHandle; use strict; sub TIEHANDLE { my $class = shift; local *FH = shift; my $sub = shift; bless { handle => *FH{IO}, routine => $sub }, $class; } sub PRINT { my $self = shift; my $fh = $self->{handle}; print $fh ($self->{routine}->(@_)); } # Not clear how to handle this! sub PRINTF { my $self = shift; my $fmt = shift; $self->PRINT(sprintf($fmt => @_)); } package main; use IO::SubHandle; sub filterText { ("Filter [@{[scalar @_]}]: ", @_); } print "This is your normal STDOUT\n"; tie *STDOUT, 'IO::SubHandle' => *STDOUT, \&filterText; print "This is your filtered STDOUT\n"; print STDOUT "This also gets filtered...\n"; print STDERR "STDERR is safe...\n"; printf STDOUT "PRINTF(pi = \%g) tied too (but #args different)\n", 3.1 +4159;

Depending on what operations you perform, you may need to tie some more methods! Note also how the printf tie probably isn't implemented "correctly"; you'll need to define precisely what it should do, then you can do it.