in reply to How to evaluate a variable in a text string

The non-strict (using symbolic references -- not recommended) way:
$val = '123'; while (<DATA>) { s/\$(\w+)/$$1/g; print; } __DATA__ test_string_$val
The strict-compliant (recommended) way:
use strict; use warnings; my %subs = (val => '123'); while (<DATA>) { s/\$(\w+)/$subs{$1}/g; print; } __DATA__ test_string_$val
Please read Why it's stupid to use a variable as a variable name

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: How to evaluate a variable in a text string
by tariqahsan (Beadle) on Mar 28, 2005 at 21:12 UTC
    Much appreciated!!!