#! /usr/bin/perl use strict; use warnings; use HTML::Parser; use Data::Dumper; my @numbers; my $string = qq~Dein HTML~; my $p = HTML::Parser->new(); $p->{numbers} = []; $p->handler(start => \&start_handler,"tagname,attr,self"); $p->handler(end => \&end_handler,"self,tagname"); $p->handler(text => \&text_handler, "self,dtext"); $p->parse($string); print Dumper(\@numbers) sub start_handler{ my ($tag,$attr,$self) = @_; return if($tag ne 'input'); return unless($attr->{name} =~ /^Button\d+$/); $self->{bool} = 1; } sub end_handler{ my ($self,$tag) = @_; if($tag eq 'td'){ $self->{bool} = 0; push @numbers,$self->{numbers} if(scalar @{$self->{numbers}} > 0); $self->{numbers} = []; } } sub text_handler{ my ($self,$text) = @_; $text =~ s/^\s+//; $text =~ s/\s+$//; if($self->{bool} and $text =~ /^\d+$/){ push @{$self->{numbers}},$text; } }