Perl Parser Error - premature end of data problems : I'm very new to both Perl and XML.  So please be patient with me.

I am running into periodic problems with a Perl sub that creates an XML request file, sends it to UPS, takes the XML response file, extracts the data, then carries on with the script.
The problem I'm finding is that occasionally it seems to get hung up on the XML.  Either it stops and posts the XML response file on the screen as a "software error", or it kicks an error that says `:2: parser error : Premature end of data in tag (insert bit of XML tag here)`

I'm guessing that the problem is from the XML request/response sub not finishing completely before the script tries to move on, but I'm not having any luck in figuring out how to avoid this, or stall the page load until the script is done.

I can't seem to recreate the error reliably enough either to debug.  I can run it, and get an error, but then the next 20/30 loads are all fine.

Is there a way to maybe watch for something to not return right and then attempt to reload the page again, or... something.  Not knowing what the problem is, i'm really stuck on not having a clue how to work around it.

I can post the sub and what not if that would help.

Thank you!