package SampleClass; sub new{ my $class = shift; my $self = {}; $self->{configFile} = shift; $self->{fileContents} = (); $self->{twig} = new XML::Twig(twig_handlers => { tag => \&tagHandler, }); bless $self, $class; } . . . sub tagHandler{ my $twig = shift; my $tag = shift; my $client_name = $tag->first_child('client')->text; my $version = $tag->first_child('version')->text; }