in reply to Keeping the script running after the Brower closes

If your problem is just that nothing gets sent to the browser until the whole script has finished, you can just insert this line before your first print:
$|=1; # Send output to browser right away

However the browser page still won't fully 'finish' until your script does, unless you do a fork.