This came up before in What encoding am I (probably) using?, but it sounds like in your case you are just choosing between latin1 and utf8? If so, the best way may be to just check if it is valid utf8, and only if it isn't assume it is latin1. You can simply use utf8::decode to do this.

In reply to Re: how to check the encoding of a file by ysth
in thread how to check the encoding of a file by jbrugger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":