my $mouse_mode; sub routine { $mouse_mode = set_mouse_mode; ... } END { if ($mouse_mode) { ... } }