#!perl use strict; use HTML::TreeBuilder; my $body = HTML::TreeBuilder->new_from_file(\*DATA); my @subsub = $body->look_down (_tag => "span"); foreach my $sss (@subsub) { my $c = $sss->attr("class"); if ($c =~ /name color/){ # ignore sub elements for ( $sss->descendants() ){ $_->detach(); }; my $name = $sss->as_trimmed_text(); print $name."\n"; } } __DATA__ ImportantText1 1000ImportantText2