A few other suggestions for you:
1) Replace the opening constants with actual constants
i.e:
$MAX_MAILS=200;
becomes
use constant MAX_MAILS => 200;
2) A fairly minor optimisation but consider replacing all double quoted strings with single quotes whereever possible
i.e.
$temp_pic= $BASEURL . "/" .
becomes
$temp_pic = BASEURL . '/' (using constants as well :P)
3) s/
\s\t\r\n+//i
Does this really need to be case insensitive - you are not matching any characters only classes of whitespace. Check all your regexes as this is an unecessary slowdown (I think :P).
4)Finally, consider using slurp mode for opening any files.
i.e.(not tested code so watch out!)
open(FH,"<$file");
my $data;
{
local $/ = undef;
$data = <FH>; # Slurrp
}
close(FH);
I would also consider putting all your sub routines into a module and create what I would term a functionality object. You can then use something like 'autouse' and have a routine for each phase of the program. You don't need to split it up then. You could also consider embedding this via mod_perl and preloading the object within Apache (assuming an apache + mod_perl host)
Hope that helps! Contact me if you need any more help :)
Simon