in reply to Executing a function on submit

You can't send the script to the client, unless you can do this all in JavaScript, which in your trivial example you probably can.

If you're doing something more ambitious, you will have to use a separate script, or one that has a "trigger" in it. Something like:
my $cgi = new CGI; # Your old stuff # : print end_form(), hr(); print_content(); print_end_html(); if ($cgi->param('DO')) { write_content(); }
Make sure that the ACTION parameter of the form is set to itself, which it should be if you don't give it any parameters. When you click on the "DO" button, it should send a DO parameter to the server with the value of the button.