in reply to Speed of opening and closing a file 1000s times

In your case, I would second the advice to open all the output files up front and write to whichever is appropriate with the caveat that you try not to recompile the regex for each possibility (i.e. store the regexen as qr// objects). In the case of larger numbers of output files, I would create a structure something like:
@natures = [{ filename => "h.ll", criterion => qr/blasphemer/, handle => undef # this line not actually needed }, ...
and open each handle as needed, with a loop at the end over natures to close them all.

Hey, wait, you could even have some kind of object encapsulating that hash, and let an object method do the match. But that starts to sound like Mail::ListDelivery/ Mail::Audit::List.