my $cp; BEGIN { ($cp) = `chcp & chcp 65001` =~ /(\d+)/ if $^O eq 'MSWin32' } END { `chcp $cp` if $^O eq 'MSWin32' }