in reply to What is the function that does the following..?

The following is based on an od.pl script I did some time ago. It does not handle Unicode characters, but I'm not sure you need that:
use warnings; use strict; my $var = "Some random text.\nMore\nEven More\n"; print process_text($var),"\n"; sub process_text { my $input = shift; # Get a space between each char my @text = split //,$input; local $" = ' '; my $text = "@text"; # Table of special characters my %trans = ("\n" => '\n', "\t" => '\t', "\b" => '\b', "\r" => '\r', "\f" => '\f'); my $pattern = join ('|', keys %trans); # substitute special characters $text =~ s/($pattern)/$trans{$1}/g; return $text; }
Produces:
S o m e r a n d o m t e x t . \n M o r e \n E v e n M o r e \n