#unicode_box_correct.pl use Win32::API; use Encode qw(from_to encode); #no need to use perlio (in this case) as we are bypassing it through the raw Win32API #binmode(STDOUT,':utf8'); #Set the console code page to UTF8 $SetConsoleOutputCP= new Win32::API( 'kernel32.dll', 'SetConsoleOutputCP', 'N','N' ); $SetConsoleOutputCP->Call(65001); #Get a reference to the console STDOUT $GetStdHandle=new Win32::API( 'kernel32.dll', 'GetStdHandle', 'N', 'N' ); $handle=$GetStdHandle->Call(-11); #Build dos window $line1="\x{2554}".("\x{2550}"x15)."\x{2557}\n"; $line2="\x{2551}".(" "x15)."\x{2551}\n"; $line3="\x{255A}".("\x{2550}"x15)."\x{255D}"; $unicode_string=$line1.$line2.$line3; print "THIS IS THE CORRECT EXAMPLE OUTPUT: \n"; #Force byte semantics because WriteFile API function needs length in bytes not characters $lengthx=length(Encode::encode_utf8($unicode_string)); #use WriteFile API to treat the Console as a file.WriteConsole won't do it $WriteFile=new Win32::API( 'kernel32.dll', 'WriteFile', 'NPNNN', 'N' ); $WriteFile->Call($handle,$unicode_string, $lengthx,0,0);