in reply to Printing escaped values of control characters

Just create a lookup table for whatever characters you consider to be control characters (why is space a control char?):

my %escaped = ( "\n" => '\n', "\r" => '\r', " " => '\s', # ... ); my $string = "1\r\n 2 \n"; while ($string =~ /(.)/sg) { my $ch = $1; $ch = $escaped{$ch} if exists $escaped{$ch}; print "Encountered character: $ch\n"; }