Subroutines, like functions in Java Script, give you an easy way to run a common function more than once in your script.
Once you place your code within a subroutine block, you can run that code as often as you like, from anywhere in the script.
In this tutorial we're going to write a CGI script that checks whether a form has been filled out correctly.
It's possible to do form validation using Java Script (see our Form validation with Java Script tutorial).
Java Script validation is nice and quick because there's no round-trip to the server; however Perl validation is more secure and reliable, because it will always work even if the browser has Java Script disabled, or if the user has managed to "hack" the Java Script validation.
In a "real-world" application you would do all your actual form processing here (sending an email, adding a record to a database table, etc).
You can view the whole script here, and see the script in action here.