my $ok_to_add_text; ... sub text_handler { ... if ($ok_to_add_text) { push ... } }