#!/usr/bin/perl use strict; use warnings; use XML::Rules; use YAML::XS; my $parser = XML::Rules->new( rules => { 'Capacities_Outpatient_Clinic, Other, Outpatient_Clinic, Outpatient_Clinic_Special, Outpatient_Services' => 'no content', 'Capacities_Outpatient_Clinic_Special' => 'pass', 'AM_Key, AM_Other_Key, AM_Special_Key, Description, Explanations, LK_Key, Type, VA_VU_Key_Outpatient_Clinic, VA_VU_Other_Key_Outpatient_Clinic' => 'content', 'Care_Point' => 'as array no content', 'Capacity' => sub {$_[1]->{LK_Key} => 1}, 'Outpatient_Service' => sub { if (exists $_[1]->{Outpatient_Clinic}) { if ( exists $_[1]->{Outpatient_Clinic}->{Other} ) { return $_[1]->{Outpatient_Clinic}->{Description} => 1 } else { return $_[1]->{Outpatient_Clinic}->{AM_Key} => 1 } } elsif ( exists $_[1]->{Outpatient_Clinic_Special} ) { my $h; for ( keys %{ $_[1]->{Outpatient_Clinic_Special} } ) { $h->{$_} = 1 if /LK\d*/; } return %$h; } else { } }, } ); my $data = $parser->parsefile(shift); print Dump $data;