Well, first of all, the usual questions ... do you have use strict; use warnings; and in that situation does it “compile cleanly?”
Next, well, there is no such thing as “sometimes, not always.” What you are dealing with here is a bug ... in your code. Somewhere. That bug is probably located in the bit of code that you elided out, the second time, with "...". I do not believe that this has anything in particular to do either with mod_perl nor the Registry.
In addition, I suggest that you should put all your code together, in subroutines, and not put subroutines in-the-middle. Let the code-paths be obvious, and contiguous.