my @hexout; foreach $line ( @raw ) { # get the hex values for uthe input line my $hvs = $line->hex; # now loop over the conversions foreach my $hexkey ( keys %keyconv ) { # if this char to be replaced is in # this line, do a conversion if ( $hvs =~ /$hexkey/ ) { # replacement chars are utf8... my $newStr8 = utf8($keyconv{$hexkey}); # ...so convert it to utf16 my $newStr16 = $newStr8->utf16; my $Str16Obj = utf16($newStr16); # and get its hex value in utf16 format my $newhex = $Str16Obj->hex; print "Replaced $hexkey with", "$newStr (hex: $newhex) in line\n", "(hex: $hvs)\n" if $debug; # do the conversion $hvs =~ s/$hexkey/$newhex/g; } } # maintain a list of output hex values. push @hexout, $hvs; }