if (defined(my $pid=fork())) { if ($pid) { # $pid is not 0, so this is the parent # Let's redirect the user. print header, start_html, h2('Sending Mail...'), "\t\n", end_html; $SIG{CHLD}='IGNORE'; exit; }else{ # $pid=0, so this is the child $retval=build_mail(); exit $retval; } }else{ # Oops, fork() returned undef - something is definitely wrong. DieNice("Unable to fork: $!\n"); } # Do your time consuming stuff, setting $retval to # a useful number sub build_mail { while (<@to>){ chomp($_); push @chunk, $_; $count ++; if ($count == 80){ #splits bcc into small chuncks $to = join ",", @chunk; mailout(); $count = 0; @chunk = (); } } $to = join ",", @chunk; mailout(); return $retval; }