my $char = 'n'; $char = sprintf("\\%s", $char); #### my $char = 'n'; $char =~ s/(n)/\\$1/;