package ChargeTypeXML; sub new { my $class = shift; my %args = shift; my $ref = XMLin($args->{file}, KeyAttr => { charge => "code"}); my %hash = map { ($_, $ref->{charge}->{$_}->{name}) } keys %{$ref->{charge}}; $ref = \%hash; bless $ref, $class; return $ref; } sub toXML { print qq{\n}; print qq{\n}; for keys ( %{$self} ) { print qq{\n}; } print qq{}; } 1; #in the script: use ChargeTypeXML; my $xml = ChargeTypeXML->new (file=>"xmlfile");