#!/usr/bin/perl $string="€"; $string = s/([^\x00-\xFF])/sprintf "&#x%x;", $1/eg; # Encode print $string;