#!/usr/bin/perl use utf8; use HTML::TreeBuilder::XPath; use warnings; use strict; my $xhtml = HTML::TreeBuilder::XPath->new; $xhtml->implicit_tags(1); $xhtml->no_space_compacting(1); my $filehandle; open ($filehandle, "< :encoding(UTF-8)", \*DATA) or die("Could not open file 'DATA' : error: $!\n"); # parse UTF-8 $xhtml->parse_file($filehandle) or die("Could not parse file handle for 'DATA' : $!\n"); close ($filehandle); print $xhtml->as_XML_indented; $xhtml->delete; exit(0); __DATA__ Foo

Abc ‘Def’ (GHI)