in reply to Code Critique

Several comments.

First, use something like Perl::Tidy to fix the indentation and formatting. It'll be easier to read that way. (I know that copying and pasting code in here sometimes changes the formatting, but it's a good habit anyway.)

Second, use strict and warnings. They can help prevent making silly mistakes and their warnings can help you to think about what you're doing and why. In particular, you use undeclared global variables and you use array slices in scalar context (which is rarely what you mean).

Third, use lexical filehandles and three-argument open. This helps avoid further global variables and avoids a potential problem (though not in this case) where untrusted input can change how your program performs IO.

Fourth, embrace Perlishness. For example, assigning to @names and then extracting elements into named variables directly is much easier if you assign to a list of those variables from the split in a single step. Likewise string interpolation is often clearer than lots of small concatenations. Similarly there's no reason to assign initial empty values to variables if you declare them as lexicals.

Once you've done that, you can reduce the busy work—I'm sure many of those substitutions are superfluous, and there's no reason to push values onto @keys if you're going to treat it as a hash anyway; make it a hash to start.

If you don't already have a good Perl 5 book, you might like to read the draft of my Modern Perl.