in reply to finding all modules used from a script

Look at the special variable %INC. Take a look at Apache::StatINC and Apache::Reload to see some examples of messing about w/ %INC, in a mod_perl context.

The keys in the hash will be in the form Foo/Bar.pm, but you can fix that with a simple regex. Then you can do your cleanup. For example:

for my $file (keys %INC) { (my $class = $file) =~ s!/!::!g; $class =~ s/\.pm$//; if ($class->can('clean_up')) { $class->clean_up; } }