#!/usr/bin/perl use strict; use WWW::Mechanize; use HTML::Parser; sub start_handler { my ( $tag, $attr, $self ) = @_; return unless ( $tag eq 'center' and $$attr{class} eq 'categories' ); $self->handler( text => sub { print shift }, 'text' ); $self->handler( end => sub { shift->eof if shift eq 'center'; }, 'tagname,self' ); } my $mech = WWW::Mechanize->new(); $mech->get("http://search.cpan.org/"); my $parser = HTML::Parser->new(api_version => 3, start_h => [ \&start_handler, "tagname,attr,self" ]); $parser->parse( $mech->content()); #### $self->handler( end => sub { if(shift eq 'center'){shift->eof} }, "tagname,self" );