for my $d ($root->findnodes($xpath)) { my @line = $d->content_list; s/^\s+|\s+$//g for @line; printf "%s\n",$line[0]; }