{ package Before; sub new { my ($sClass,$f) = @_; my $fBefore= sub { print "Special stuff for class $sClass\n"; goto &$f }; return bless($fBefore,$sClass); } } { package AlsoBefore; our @ISA=qw(Before); } my $f1=Before->new(sub {print "Hello world!\n"}); my $f2=Before->new(sub {print "Bonjour, le monde!\n"}); my $f3=Before->new(sub {print "Guten tag, die welt!\n"}); my $f4=AlsoBefore->new(sub {print "Boker tov, olam!\n"}); $f1->(); $f2->(); $f3->(); $f4->(); #### Special stuff for class Before Hello world! Special stuff for class Before Bonjour, le monde! Special stuff for class Before Guten tag, die welt! Special stuff for class AlsoBefore Boker tov, olam!