in reply to "pack" string read from command line

If you just want \x escapes, you can use a regex:
#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; my $string = 'foo\x32\x33\x34bar'; $string =~ s/\\x([0-9a-f][0-9a-f]?)/chr hex $1/gie; say $string;

I wouldn't recommend eval.

Update: For full functionality, see String::Interpolate.

use String::Interpolate qw{ interpolate }; say interpolate($string);
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: "pack" string read from command line
by demoralizer (Beadle) on Nov 19, 2015 at 08:51 UTC
    Thanks a lot for answering that fast!

    Doing it manually is a little bit to simple because the string could also contain stuff like "\n".

    String::Interpolate is exactly what I need.
Re^2: "pack" string read from command line
by BillKSmith (Monsignor) on Nov 19, 2015 at 13:59 UTC
    I wish that I had known this several years ago! I still may be able to use your advice to demoralizer to improve an existing program.
    Bill