in reply to Encoding question

Perl has two types of strings. Strings of bytes and strings of characters. You wish to match characters, but you're matching bytes. Decode (using Encode's decode function, for example) the bytes into characters.
use Encode qw( decode ); my $bytes = "x\0m\0l\0"; print(length($bytes), "\n"); # 6 my $chars = decode('utf16le', $bytes); print(length($chars), "\n"); # 3 print($chars =~ /xml/ ?1:0,"\n"); # 1

Update: Oops, I had utf8 instead of utf16le originally. utf16 will also work with the original string since it contained a BOM.