use warnings; use strict; my $mp = MyPrint->new(*STDERR); $mp->myprint("foobar\n"); myprint $mp "foobar\n"; package MyPrint; sub new { my ($class, $out) = @_; return bless { out => $out }, $class; } sub myprint { my ($self, $text) = @_; my $out = $self->{out}; print $out $text; }