Welcome to PerlMonks!
First, thanks for making the effort to make your code block legible, but please note that <pre> tags are discouraged here. If you want something displayed in fixed-width font, please use <code> tags. Writeup Formatting Tips and Perl Monks Approved HTML tags are good references.
Here are some general observations that may help you with this and future programs.
- use strict; It will help you avoid bugs.
- Limit the scope of your variables. Adding strictures and declaring all of your variables with "my" is a good start, but it doesn't help as much if they are all in file scope (not in blocks).
- When you die, you probably want $!, not $_.
- Kudos on checking the return value of open! The 3-argument form of open with a lexically-scoped filehandle might be a better way to go: open( my $fh, '<', $filename ) or die $!;
- Note that you don't need to quote variables for things like die $!; and print $hits;
- When you read the $code file you chomp each line, but then you add a newline right back on when you print it. Unless there is code between those lines that you aren't showing us, you can skip both steps.
- Instead of printing out the HTML, consider using a module (like CGI) to do it for you. It is much more robust and it will clean up your code. It will also help you avoid errors like forgetting to put in a starting <HTML> tag (although it may be in the $code file). :-)
HTH. Please don't be discouraged by these comments. We all learned the basics at one point. :-)