in reply to how to compile it

does the .pm extension tell the webserver that it is a perl file and needs to be compiled as perl?
No - there are many other factors involved. Usually what you would do is:

1. Make the first line of your program reads #!perl. In some cases you might need to put the full path to perl on this line: #!/usr/local/bin/perl.

2. Make sure it is executable (i.e. use chmod)

3. Name your program myscript.cgi (.cgi is a common suffix for CGI programs).

4. Ensure that your web server will treat files ending in .cgi as CGI programs.

Sometimes scripts need to reside in a special directory in order to be treated as CGI scripts. Check your web server's configuration (or change it.)