in reply to Re^2: CGI.pm: "Malformed UTF-8 character" in apache's error.log
in thread CGI.pm: "Malformed UTF-8 character" in apache's error.log

Fixed:

... my $fh_in = $cgi->upload('file'); binmode $fh_in, ':encoding(UTF-8)'; open(my $fh_out, '>:encoding(UTF-8)', "/var/www/mypath/$filename") or die $!; while (<$fh_in>) { print $fh_out $_; }

But there's absolutely no reason to convert to chars in the above code, so you'd be better off as

... my $fh_in = $cgi->upload('file'); open(my $fh_out, '>', "/var/www/mypath/$filename") or die $!; while (<$fh_in>) { print $fh_out $_; }

You also mentioned binary uploads (like MP3s). For that, you'd use

... my $fh_in = $cgi->upload('file'); open(my $fh_out, '>', "/var/www/mypath/$filename") or die $!; binmode $fh_in; binmode $fh_out; local $/ = \4096; # Don't wait to find "\n" while (<$fh_in>) { print $fh_out $_; }

The code for binary files also works with text files.