Installing Apache2/Modperl on Ubuntu 12.04

apt-get install apache2
apt-get install libapache2-mod-perl2
apt-get install perl-debug
apt-get install libapache2-mod-perl2-dev
apt-get install  libapache2-request-perl libdatetime-perl 

Edit /etc/apache2/sites-available/default, add:

        <Location /perl/>
                SetHandler perl-script
                PerlHandler ModPerl::PerlRun
                Options ExecCGI
                PerlSendHeader On
                allow from all
        </Location>

Install the CGI module:

cpan install CGI

Create a directory /var/www/perl. Add a script, for example:

#!/usr/bin/perl

use CGI;                             # load CGI routines
$q = CGI->new;                        # create new CGI object
print $q->header,                    # create the HTTP header
      $q->start_html('hello world'), # start the HTML
      $q->h1('hello world'),         # level 1 header
      $q->end_html;                  # end the HTML

Call it something like hello.pl. Try to access http://server/perl/hello.pl, everything should work correctly.