# RGB format a text document using a highlight colour. # RGB 0-255 like HTML 0x00-0xFF # Output should be valid RTF but YMMV sub RTFhighlight { my ($text, $highlight, $r, $g, $b, $font) = @_; $font ||= "Arial"; $text =~ s/([\\{}])/\\$1/g; # escape \ and { } $text =~ s/\n/\\par\n/g; # convert \n to \par $text =~ s/\b\Q$highlight\E\b/\\cf1 $highlight\\cf0 /g; my $header = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fswiss\\fcharset0 $font;}}\n"; $header .= "{\\colortbl ;\\red$r\\green$g\\blue$b;}\n"; return $header.$text; } print RTFhighlight("hello be seabe be because", "be", 0, 0, 0xFF);