... use HTML::Parser; my $parser = HTML::Parser->new; $parser->handler( start => \&start_handler, 'tagname, self' ); $parser->parse( $content ); sub start_handler { return if shift ne 'li'; my $self = shift; $self->handler( start => \&title_handler , 'tagname, attr' ); sub title_handler { return if shift ne 'a'; my $title = shift->{title}; return unless $title; if ( $title =~ /\Q$name\E/sm ) { say $title; } } }