my @fh = $query->upload("photo"); foreach $fhan(@fh){ open (UPLOADFILE, ">$upload_dir/$filename") or error($!); binmode UPLOADFILE; while ( <$fhan> ) { # Huh? $fhan is a variable, not the filehandle # Wait. You're printing what to where? # You should be using an img tag and providing # file path to the file in src or providing the binary # data in src print UPLOADFILE; } # end of while loop # Wait, we're approaching the end of the foreach loop # that starts with opening a file, but where's the code # to close the file? } # end of foreach loop # Need to move this close statement inside the foreach at # the end of each iteration close UPLOADFILE;