http://qs321.pair.com?node_id=1162842


in reply to Perl on Windows: file names with accented characters, UTF-8 and -e

Your understanding is correct. Everything depends on which Encoding is used to store file names in your Windows (well on Linux also, but normally Linux uses only UTF-8, but there are some exotic cases). You can try to use some standard modules mentioned by others. Or you can try to play with encodings of strings. There's very powerful and simple module Encode that comes with perl. Use that module to convert your strings to desired encoding.

There's one tricky point though. Perl can be configured to automatically apply conversion to data received from OS. That automatic conversion may be wrong and/or may confuse. In general, OS passes to perl "octets", perl may convert them to "characters" (automatically or per request). Normally when working with file names also perl has to pass to OS "octets".

So, if you know that you get data from file in UTF-8 encoding and Windows encodes file names using CP1252, then you'd have to do the following

Encode::from_to($fname, "UTF-8", "CP1252");
But the above code assumes that $fname contains "octets" (Encode::is_utf8($fname) returns false). If it already contains "characters", then the code shall be
$fname = Encode::encode("CP1252", $fname);

Read through perldoc Encode to get the details.