in reply to Simplifying the following code

If you put all of your files into an array instead of an individual variable for each, you could iterate through your array.
<input name='file' ...> <input name='file' ...> <!-- instead of doing file1, file2 --> <input name='file' ...> my @files = $cgi->param('file'); foreach (@files) { # process as needed or just use as-is }