#!/usr/bin/perl use strict; use warnings FATAL => "all"; use XML::Simple; my $xml = ' 5 35 some text 4 45 some text 3 25 maps 2 15 some text '; my $ref = XMLin($xml); for my $cm(@{$ref->{'contentmodel'}}){ printf "%d\n", $cm->{'first'} if $cm->{'content'} eq 'maps' }; __END__ output 25