Question: For example I have, 

```
my $str = '\t';
print "My String is ".$str;

```

I want the output to interpret the tab character and return something like:

```
"My String is \t"

```

I am actually getting the value of the string from the database, and it returns it as a single quoted string.

Answer: 
`'\t'` and `"\t"` are *string literals*, pieces of Perl code that produces *strings* ("\","t" and the tab character respectively). The database doesn't return Perl code, so describing the problem in terms of single-quoted literals and double-quoted literals makes no sense. You have a string, period.

The string is formed of the characters "\" and "t". You want to convert that sequence of characters into the tab character. That's a simple substitution.

```
s/\\t/\t/g

```

I presume you don't want to deal with just `\t`. You can create a table of the sequences.

```
my %escapes = (
    "t" => "\t",
    "n" => "\n",
    "\" => "\\",
);

my $escapes_pat = join('', map quotemeta, keys(%escapes));
$escapes_pat = qr/[$escapes_pat]/;

s/\\($escapes_pat)/$escapes{$1}/g;

```
Well, I just tried below workaround it worked. Please have a look

```
my $str1 = "1234\n\t5678";
print $str1; 
#it prints 
#1234
#     5678

$str1 =~ s/\t/\\t/g;
$str1 =~ s/\n/\\n/g;

print $str1; 
#it prints exactly the same
#1234\n\t5678

```