Take a look at Re: Exiting takes a looong time (by the man that knows) and see if that is applicable.
In reply to Re: undef quite slow? by BrowserUk in thread undef quite slow? by glwtta