in reply to Evaluating a regex replacement value

The above responses correctly suggest the /e modifier... though as i interperet OP's needs, "KEYWORD" needs to be used to get the value (i'll assume via a hash, but could be a function call or something else) ...
use strict; use warnings; my %values = ( foo => 3, bar => 4, stuff => 5 ); while( <DATA> ){ s/<:(KEYWORD):(?:([^:>]+:)?>/ $values{$1} * ($2 || 1) /e; print; } __DATA__ <:foo:4:> <:bar:5:> <:bar:> <:stuff:9:> # OUTPUT: 12 20 4 45
one last note to OP: if your intent was like above, but instead of a hash you have variables named $foo, $bar, and $stuff and those are what you want used, then it is possible to do eval('$'.$1), but not recommended -- it is probably better to rework the code to use a hash or function call to look of the value instead.