sub upload_image { ## pull the file in a variable my $fh = $query->upload('upload'); ## determine the file type via the headers my $type = $query->uploadInfo($fh)->{'Content-Type'}; ## take action based on type if ($type eq 'text/html') { ## 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, ">/www/$destination{$formdata{filename}}") or die "Cant open HTML file for writing : $!\n"; ## if file is determined to be text/html write contents to appropriate location while(<$fh>) { print HTML "$_\n"; } close(HTML); ## otherwise set error for later notification within html } else { $error = "on"; } }