package class; sub metthod { ... } sub constructor or method { ... if( some condition) { *{class::method} = sub { ... }; } }