Hopefully a more complete and self contained example for haukex explanation:

#!/usr/bin/env perl use v5.10; use strict; use warnings; use Math::BigInt; use constant offset => Math::BigInt->new('0x500000000'); while (my $line1 = <DATA>) { # if addr 0x10000 written like 0x010000 then # 0x(?:[[:xdigit:]]{2})+)\b may validate memory address my ($addr) = $line1 =~ /addr:(0x[[:xdigit:]]+)\b/; # print "addr is $addr\n"; if (defined $addr) { my $new_addr = sprintf "0x%x", hex($addr) + offset; if ($line1 =~ s/ \baddr: \K $addr (?=\s+qospri:) /$new_addr/x ) { print $line1; } else { print STDERR "unchanged\n"; print $line1; } } } __DATA__ chn:req mon:orig cmd:SDP_CMD_WRSIZEDFULL tag:0x3b9aca01 addr:0xdf7780 +qospri:0 len:0xf

Update: requirement for even number of digits removed thanks to explanation from AnamalousMonk.

Ron

In reply to Re: Performing addition on hex value extracted from a string by mr_ron
in thread Performing addition on hex value extracted from a string by syedasadali95

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.