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: 
You can follow the technique in [perlfaq4](http://faq.perl.org/perlfaq4.html)'s answer to [How can I expand variables in text strings?](http://faq.perl.org/perlfaq4.html#How_can_I_expand_var):

---

If you can avoid it, don't, or if you can use a templating system, such as Text::Template or Template Toolkit, do that instead. You might even be able to get the job done with sprintf or printf:

```
my $string = sprintf 'Say hello to %s and %s', $foo, $bar;

```

However, for the one-off simple case where I don't want to pull out a full templating system, I'll use a string that has two Perl scalar variables in it. In this example, I want to expand $foo and $bar to their variable's values:

```
my $foo = 'Fred';
my $bar = 'Barney';
$string = 'Say hello to $foo and $bar';

```

One way I can do this involves the substitution operator and a double /e flag. The first /e evaluates $1 on the replacement side and turns it into $foo. The second /e starts with $foo and replaces it with its value. $foo, then, turns into 'Fred', and that's finally what's left in the string:

```
$string =~ s/(\$\w+)/$1/eeg; # 'Say hello to Fred and Barney'

```

The /e will also silently ignore violations of strict, replacing undefined variable names with the empty string. Since I'm using the /e flag (twice even!), I have all of the same security problems I have with eval in its string form. If there's something odd in $foo, perhaps something like @{[ system "rm -rf /" ]}, then I could get myself in trouble.

To get around the security problem, I could also pull the values from a hash instead of evaluating variable names. Using a single /e, I can check the hash to ensure the value exists, and if it doesn't, I can replace the missing value with a marker, in this case ??? to signal that I missed something:

```
my $string = 'This has $foo and $bar';

my %Replacements = (
    foo  => 'Fred',
    );

# $string =~ s/\$(\w+)/$Replacements{$1}/g;
$string =~ s/\$(\w+)/
    exists $Replacements{$1} ? $Replacements{$1} : '???'
    /eg;

print $string;

```
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

```