http://www.perlmonks.org?node_id=222067


in reply to Unicode, regex's, encodings, and all that (Perl 5.6 and 5.8)

Yes, 'use encoding'/'no encoding' are per script, but not per block lexical. However your interpretation/understanding is wrong. The following examples could help you to understand:
  1. In a package, if you say:
    ... (block 1)
    use encoding "greek";
    ... (block 2)
    no encoding;
    ... (block 3)
    
    The actual effect is encoding in block 2, but no encoding in block 1, and 3. It is not as you expected that, becasue that no encoding comes the last, the whole module is no encoding.
  2. In a package, if you say:
    ... (block 1)
    use encoding "greek";
    ... (block 2)
    use encoding "greek";
    ... (block 3)
    no encoding;
    ... (block 4)
    
    The actual effect is encoding in block 2 and 3, but no encoding in block 1 and 4. Again, according to your interpretation, the whole module is not encoding becasue that 'no encoding' is the last in the physical sequence. And again your interpretation is wrong.
  3. NOW WHAT DOES THAT SENTENCE IN "encoding" documentation MEAN? Let's get to the point:

    In packageA, you say:
    ...(block 1)
    use encoding "greek";
    ...(block 2)
    
    In a script, you say:
    use packageA;
    ...(block3)
    
    In this example, you should expect, block 1 not encoding, block 2 encoding. Block 3? Now this is what the document means: block 3 is encoding, because that use encoding in packageA is not block lexical, but per script, and your script now 'contains' packageA, that use encoding you put in packageA does affect the rest of the script, not just to the end of packageA.
  4. Another example: In packageA, you say:
    ...(block 1)
    use encoding "greek";
    ...(block 2)
    
    In a script, you say:
    use packageA;
    ...(block3)
    no encoding;
    ...(block 4)
    
    It would be encoding in block 2 and 3, no encoding in 1 and 4. The reason block 3 is encoding is that, the 'use encoding' you put in packageA is per script, so it even affects things outside the package, until meets a 'no encoding' later in the script.
  5. Last example, and this is what you are supposed to do in the best practice.

    In packageA, you say:
    ...(block 1)
    use encoding "greek";
    ...(block 2)
    no encoding; # at the end of packageA
    
    In a script, you say:
    use packageA;
    ...(block 3)
    use encoding "greek";
    ...(block 4)
    
    Block 1, 3 not encoing, 2 and 4 encoding, exactly meets what you visually see on the screen, what you see is what you get. So the best practice is to always say "no encoding" at the end of your module, if you said any "use encoding" earlier in your module. This makes sure that your module's encoding does not affect any other module/script unexpectedly.