in reply to Possible to refer to variable defined later in script?

Wouldn't the simple (and sane) thing be to output the HTML after you have processed your input and given values to variables? Also, you may want to consider using HTML::Template or similar to separate your Perl code from your HTML/CSS/JS.

You could also consider making this a dynamic page rather than writing a static HTML file each time the script runs. Though this may be out of scope for this coursework.

Update:

I don't know if this is your entire code, but I'd suggest adding use strict; use warnings; (see Use strict and warnings or search for more), ensure you're opening files properly by checking for errors, for example:

open (LOG, '<', 'IN-access.log') or die "cannot open < IN-access.log: +$!";

Such things help prevent facepalm.