sub write_flag { print "write_flag\n"; } sub set_tree { print "set_tree\n"; } sub do_nothing { print "do_nothing\n"; } ... code you provided ... build_sth('set_to_flag'); # Prints write_flag