#!/usr/bin/perl use HTML::TreeBuilder::XPath; use strict; use warnings; my $root = HTML::TreeBuilder::XPath->new; $root->parse_file(\*DATA) or die("Could not parse the data: $!\n"); $root->eof(); my $xpath = '//div/p'; for my $d ($root->findnodes($xpath)) { print $d->as_trimmed_text,qq(\n) if (defined($d->as_text)); } $root->delete; exit(0); __DATA__

foo01
bar01

foo02
bar02

foo03
bar03