use HTML::TokeParser::Simple; my $p = HTML::TokeParser::Simple->new( $ARGV[0]); my $state = ''; my %content; while ( my $tkn = $p->get_token ) { if ( $tkn->is_start_tag( 'title' )) { $state = "inTitle"; } elsif ( $tkn->is_start_tag( 'h1' )) { $state = "inH1"; } elsif ( $tkn->is_end_tag( 'title' ) or $tkn->is_end_tag( 'h1' )) { $state = ''; } elsif ( $tkn->is_text( ) and $state ) { $content{$state} .= $tkn->as_is; } } print "Title: $content{inTitle}\n"; print "H1: $content{inH1}\n";