#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; use XML::LibXML; my $dom = 'XML::LibXML'->load_xml(location => shift); my $root = $dom->getDocumentElement(); my ($bfm) = $root->findnodes('//breakfast_menu'); say for $bfm->findnodes('(following-sibling::* | preceding-sibling::*)');