#!/usr/bin/perl use warnings; use strict; use threads; use threads::shared; my $tgo; my $tdie; my $tfile; share $tgo; share $tdie; share $tfile; $tgo = 0; $tdie = 0; $tfile = ''; my $thread = threads->new(\&querySystem); foreach my $file('xmlfile.xml', 'xmlfile.xml' ){ $tfile = $file; $tgo = 1; sleep 5; } $tdie = 1; $thread->join; print "done press any key to exit\n"; <>; ################################################### sub querySystem { use XML::Twig; $|++; my $statusTwig = new XML::Twig( twig_roots => {'Result/Status' => sub{ my($twig, $element) = @_; my $mmsVersion = $element->first_child('MMSVersion')->text; my $partVersion = $element->first_child('ParticipantVersion')->text; print "mmsVersion: $mmsVersion, partVersion: $partVersion\n"; } }, ProtocolEncoding=>"x-sjis-unicode"); while(1){ if($tdie == 1){ goto END }; if ( $tgo == 1 ){ my $result = $statusTwig->safe_parsefile($tfile); $tgo = 0; #turn off self before returning }else { sleep 1 } } END: } __END__