use 5.012; use strict; use warnings; use Ask qw(:all); use XML::LibXML 2; my $xml = XML::LibXML->load_xml(IO => \*DATA); my $who = entry("Who are you looking for?"); my ($person) = $xml->findnodes(qq{//person[name/text() = "$who"]}) or error("Cannot find '$who'\n") and die; my @lines = $person->findnodes(qq{adr/*})->map(sub { $_->textContent }); info(join "; ", @lines); __DATA__ Barack Obama 1600 Pennsylvania Avenue Northwest Washington DC 20500 United States David Cameron 10 Downing Street London SW1A 2AA United Kingdom