sub upload_image { ## pull the file in a variable my $fh = $query->param('upload'); ## determine the file type via the headers my $info = $query->uploadInfo($fh); my $type = $info->{'Content-Type'}; ## take action based on type if ($type =~ m|text/html|i) { ## hash of file names to write to my %destination = ( 'match' => "match.html", 'no_match' => "no_match.html"); ## open the file to be written open(HTML, ">/path/to/$destination{$formdata{fi lename}}") or die "Cant open HTML file for writing : $!\n"; ## if file is determined to be text/html write contents to appropriate locat ion while(<$fh>) { print HTML "$_\n"; } close(HTML); ## otherwise set error for later notification within html } else { $error = "|$type|"; } }