Replace names in strings with unicode chars
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



Unicode::CharNames::Replace - Replace unicode charnames with characters at runtime


version 0.001


use Unicode::CharNames::Replace qw( replace_charnames );

my $str = replace_charnames($input, \%options);


This module provides functions for replacing unicode character names with their corresponding characters at runtime.

The charnames pragma provides a way to place "\N{CHARNAME}" into strings, but it does this at compile time. This module will search for character names in strings created dynamically during your program's execution, for example, from user input.

The use-case that was the impetus for this module is the provided unirep script which replaces charnames with characters from @ARGV or <STDIN>.


The following options can be passed to "replace_charnames" (or specified during import):

  • delimited - Replaces delimited character names in the string.

This will find sequences like "\N{CHARNAME}" and replace them with unicode characters much like charnames.

"i \N{HEAVY BLACK HEART} perl" => "i ❤ perl"
  • bare - Replaces bare character names found in the string.

Character name sequences do not need to be delimited:

"i HEAVY BLACK HEART perl" => "i ❤ perl"
  • insensitive - Matches names in a case-insensitive manner.

    "i heavy black heart perl" => "i ❤ perl"

  • noboundaries - Does not require charnames to occur at word boundaries.

    "iheavy black heartperl" => "i❤perl"


  • unirep - Command line version that works like echo or cat


  • relax perl version requirement (currently 5.14)
  • Rename methods
  • Document methods
  • Create OO interface
  • Probably replace Sub::Exporter with a simple closure around an OO instance
  • Allow for escaping the opening delimiter?
  • If delimited item is not exact, try matching as a regexp
  • By default ignore non-printing characters (CHARACTER TABULATION, LINE FEED (LF), SPACE, NULL) to avoid confusion
  • aliases? is this necessary beyond the alias functionality of charnames?
  • get list of aliases from charnames for replace_bare
  • a set of default aliases (heart, poo, razzberry)?
  • options for limiting charnames to specfied scripts/blocks?
  • options for matching omitted (specified) prefix?
  • move app into package to make it easy to wrap: use charnames :alias => ...; Unicode::Charnames::Replace::App->run;



You can find documentation for this module with the perldoc command.

perldoc Unicode::CharNames::Replace


The following websites have more information about this module, and may be of help to you. As always, in addition to those websites please use your favorite search engine to discover more resources.

  • Search CPAN

The default CPAN search engine, useful to view POD in HTML format.

  • RT: CPAN's Bug Tracker

The RT ( Request Tracker ) website is the default bug/issue tracking system for CPAN.

  • CPAN Ratings

The CPAN Ratings is a website that allows community ratings and reviews of Perl modules.

  • CPAN Testers

The CPAN Testers is a network of smokers who run automated tests on uploaded CPAN distributions.

  • CPAN Testers Matrix

The CPAN Testers Matrix is a website that provides a visual overview of the test results for a distribution on various Perls/platforms.

  • CPAN Testers Dependencies

The CPAN Testers Dependencies is a website that shows a chart of the test results of all dependencies for a distribution.

Bugs / Feature Requests

Please report any bugs or feature requests by email to bug-unicode-charnames-replace at, or through the web interface at You will be automatically notified of any progress on the request by the system.

Source Code

git clone


Randy Stauner


This software is copyright (c) 2011 by Randy Stauner.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.