do_a(); my::Error::register(\&undo_a); if ($do_c) { do_c(); my::Error::register(\&undo_c); } do_b(); my::Error::register(\&undo_b);