in reply to Regex substitute with both a sub and other data

Just put a normal Perl expression to the pattern with /e.
$xml =~ s/(\<tag\>)(\d{11})(\<\/tag\>)/ $1 . md5_hex($2) . $3 /eg;

Update: Or, use a proper XML handling tool:

{ package XML::XSH2::Map; use Digest::MD5 qw( md5_hex ); } use XML::XSH2; xsh << '__XSH__'; open 1.xml; for my $n in //num[xsh:matches(., '^[0-9]{11}$')]/text() { my $s = string($n); insert text { md5_hex($s) } replace $n ; } ls / ; __XSH__
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Regex substitute with both a sub and other data
by FloydATC (Deacon) on Aug 23, 2013 at 10:41 UTC
    So simple. *smack*... Thanks both of you :-D

    -- FloydATC

    Time flies when you don't know what you're doing