use v5.22; use warnings; # Causes "Wide Character.." warning for :std #use utf8; my %swaps = ( '91' => '‘', '92' => '’', '94' => '”', '96' => '–', 'A9' => '©', ); while (my $line = ) { say "Before=".$line; # Works. #my ($key) = $line =~ m/(\x92)/; # All fail #my ($key) = $line =~ /(\\x[[:xdigit:]]{1,3})/; #my ($key) = $line =~ m/(\x\d{2})/; #my ($key) = $line =~ /(0x[0-9A-F]{1,3})/i; #my ($key) = $line =~ m/(0x\d{1,3})/; #my ($key) = $line =~ m/(\0x\d{1,3})/; my ($key) = $line =~ m/0x(?-i:[\da-f]+)/; say "Key=$key"; $line =~ s/$key/$swaps{$key}/g if $key; say "After=".$line; } # This sample has \x92 between "heart" and "s". # In xxd, the line looks like this # 0000080: 6420 7061 6e73 792c 2068 6561 7274 9273 d pansy, heart.s __DATA__ "Wild pansy (Viola tricolor), 19th century illustration","19th-century hand painted illustration of wild pansy, heart<92>s ease, or love in idleness (Viola tricolor) flower by Pierre-Joseph Redoute (1759-1840). Published in Choix Des Plus Belles Fleurs, Paris (1827).",N/A,"Pansy, pansies, wild, Viola tricolor, 19th century, painted, Engraving, illustration, nobody, no-one, flower, artwork, Pierre Joseph redoute, bloom, blossom, botanical, botanist, bud, flora, floral, history, historic, horticulture, leaves, petal, petals, plant, vintage, watercolor, flower head, painting, stem, victorian style, botanic, flowers, plants, Botany",,C,Fl,N/A,,,,^M