#!/usr/bin/perl { package foo; sub new { my $type = shift; return bless {}, $type; } sub baz { print "foo-baz\n"; } sub m { my $self = shift; # do some init here print "replace\n"; *m = sub { $self->baz }; $self->m(); } } { package bar; use base foo; sub baz { print "bar-baz\n"; } } # main my $x = new foo; my $y = new bar; $x->m; $y->m;