#!/usr/bin/perl use strict; use RTF::Writer; die "Usage: $0 file.txt\n (this will create file.rtf)\n" unless ( @ARGV and $ARGV[0] =~ /\.txt$/ and -f $ARGV[0] ); # input file is expected to be utf8 open( I, "<:utf8", $ARGV[0] ) or die "$ARGV[0]: $!"; my $utf = do { local $/; }; # slurp it # here's the magic part: replace each wide character with # "\uN\5f", where "N" is the decimal numeric codepoint: $utf =~ s/([^[:ascii:]])/sprintf("\\u%d\\'5f",ord($1))/eg; ( my $out = $ARGV[0] ) =~ s/txt$/rtf/; my $rtf = RTF::Writer->new_to_file( $out ); my @pars = split( /\n+/, $utf ); $rtf->prolog( title => $out ); for my $par ( @pars ) { $rtf->paragraph( \$par ); # need to pass $par by reference } $rtf->close;