You can use the following HTML to load a script from a file:
<script src="/path/to/file.js"></script>
Note that /path/to/file.js is relative to the document root of your webserver, and is not an absolute path on your filesystem.
As you may have noticed, embedding HTML/CSS/JavaScript in your Perl scripts is not very maintainable. I would recommend keeping your CSS and JavaScript in separate, static files and using a template library like Template Toolkit to generate your HTML. Using templates helps you separate your presentation logic from your business logic, and saves you from having to use CGI.pm's arcane methods of generating complex HTML.
Here's an example using Template Toolkit to populate the path to your JavaScript file at runtime:
foo.cgi
use strict;
use warnings;
use CGI;
use Template;
my $tt = Template->new or die Template->error;
my $q = CGI->new;
print $q->header;
my $js_file = '/path/to/file.js';
$tt->process('foo.tt', { js_file => $js_file }) or die $tt->error;
foo.tt
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello, Template Toolkit!</title>
<script src="[% js_file %]"></script>
</head>
<body>
<h1>Hello, Template Toolkit!</h1>
</body>
</html>
Output
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello, Template Toolkit!</title>
<script src="/path/to/file.js"></script>
</head>
<body>
<h1>Hello, Template Toolkit!</h1>
</body>
</html>