That depends what you mean by later. Perhaps something like the following would work for you?
sub start_handler {
my $self = shift;
my $tagname = shift;
my $attr = shift;
my $text = shift;
my $variable = '';
return unless ( $tagname eq 'div' and $attr->{id} eq 'body' );
$self->handler( start => sub { $variable .= shift }, "text" );
$self->handler( text => sub { $variable .= shift }, "text" );
$self->handler(end => sub {
my ($endtagname, $self, $text) = @_;
if($endtagname eq $tagname) {
later($variable);
$self->eof;
} else {
$variable .= $text;
}
}, "tagname,self,text");
}
sub later {
my ($variable) = @_;
## do something with $variable
}