in reply to scope of variable

For me, some information is missing before your puzzle can be solved:

  1. Are you running under use strict;?
  2. Where do you declare my $d;?
  3. Are you sure that your print statements are executed in order suggested? I would feel more comfortable if you had print "1:$d"; for your print1 etc. The parser might call your functions in a different order than expected or suggested by the names. (I have not checked on the documentation of XML::Parser.)