use strict; use warnings; my $text = join '', ; my %replacements = ( 'romeo' => 'CountZero', 'juliet' => 'Elisabeth', 'rom.' => 'CountZero', 'jul.' => 'Elisabeth', 'abram' => 'Igor', 'abr.' => 'Igor', ); $text =~s/%%([^%]+)%%/replace($1)/ge; print $text; sub replace { my ($needle) = @_; return "%%$needle%%" if ! exists $replacements{lc $needle}; return $replacements{lc $needle}; } __DATA__ (follows the full Project Gutenberg e-text of Shakespeare's %%Romeo%% and %%Juliet%%; found at http://www.gutenberg.org/dirs/etext97/1ws1610.txt) #### (follows the full Project Gutenberg e-text of Shakespeare's CountZero and Elisabeth; found at http://www.gutenberg.org/dirs/etext97/1ws1610.txt)