Understanding lexical scoping of "use open ..." of Perl <pre><code>use open qw( :encoding(UTF-8) :std ); </code></pre> <p>Above statement seems to be effective in its lexical scope only and should not affect outside of it's scope. But I have observed the following.</p> <pre><code>$ cat data € </code></pre> #1 <pre><code>$ perl -e ' open (my $fh, "&lt;encoding(UTF-8)", "data"); print($_) while &lt;$fh&gt;;' Wide character in print at -e line 1, &lt;$fh&gt; line 1. € </code></pre> <p>The <code>Wide character ...</code> warning is perfect here. But</p> #2 <pre><code>$ perl my ($fh, $row); { use open qw( :encoding(UTF-8) :std ); open ($fh, "&lt;", "data"); } $row = &lt;$fh&gt;; chomp($row); printf("%s (0x%X)", $row, ord($row)); € (0x20AC) </code></pre> <p>Does not show the wide character warning!! Here is whats going on here imo</p> <ul> <li>We are using open pragma to set the IO streams to UTF-8, including STDOUT.</li> <li>Opening the file inside the same scope. It reads the character as multibyte char.</li> <li>But printing outside the scope. The print statement should show "Wide character" warning, but it is not. Why?</li> </ul> <p>Now look at the following, a little variation</p> #3 <pre><code>my ($fh, $row); { use open qw( :encoding(UTF-8) :std ); } open ($fh, "&lt;", "data"); $row = &lt;$fh&gt;; chomp($row); printf("%s (0x%X)", $row, ord($row)); â¬ (0xE2) </code></pre> <p>Now this time since the open statement is out of the lexical scope, the <code>open</code> opened the file in non utf-8 mode.</p> <p>Does this mean <code>use open qw( :encoding(UTF-8) :std );</code> statement changes the STDOUT globally but STDIN within lexical scope?</p>