use XML::Simple; my $str = " desc notExpected.jpg head correctImage.jpg"; my $xml = XMLin( "$str" ); my $image = $xml->{image}; print "$_\n" for ref( $image ) ? @{$image} : $image;