#!/usr/bin/perl use warnings; use strict; my $text = "Hallo\t\r\nWelt foo"; my %symbols = ( ord " " => '[SPACE]', ord "\n" => '\n', ord "\t" => '\t', ord "\r" => '\r', ); while ( $text =~ m/\G (\S*) (\s) (\S*) /gx ) { print $1, $symbols{ ord($2) }, $3; } print "\n";