in reply to How do you uncover needless module loads or missing loads in code.

First things first, I would look at why a script is going kaboom when something is no longer used. Isolate the problematic design pattern and then replace it with something that is not so delicate. Under normal coding circumstances a loaded but unused module simply sits there, not bothering anyone. At worst it takes up a small amount CPU cycles to compile and a bit of memory to keep around, but that is about the cost of it.

For example, if the script is going kaboom because the module no longer exists on your system, maybe you want to replace use blah with something that checks first to see if the module is on the system before trying to load it. There are a large number of modules on CPAN that can be used to construct something like that. Among them: Module::Optional, Module::Pluggable, Module::Best, Module::maybe, Module::only, Module::Load::Conditional.

Trying to find loaded but unused modules is not an easy task, even in strongly typed languages like Java. At best you will get approximate results:

If estimates are OK for your purposes, then you might want to take a look at PPI. However, make very sure you have a very good test suite that covers all code and considers all configuration files that might affect what modules are loaded. Otherwise, you may find you nixed a dependency that is in fact in use. Been there. Done that.

Best, beth