You have a couple of bugs in your regex. You are missing the closing '/'.

You need an e flag to evaluate the substitution expression. However as it stands that gets messy because of the mixture of string litteral characters and characters that represent a calculation. No way Perl can disambiguate that!

I'd be inclined to do it like this:

use strict; use warnings; my $str = "<tag1>Complete</tag1><tag2>3386</tag2><tag3>77844</tag3><ta +g4>11</tag4><tag5>30</tag5><tag6>4.7</tag6>"; if ($str =~ m|<tag1>Complete</tag1>|) { $str =~ s|(?<=<tag6>)(.*?)(?=</tag6>)|$1 * 100|e; } print $str;

Prints:

<tag1>Complete</tag1><tag2>3386</tag2><tag3>77844</tag3><tag4>11</tag4 +><tag5>30</tag5><tag6>470</tag6>

Note the use of strictures (use strict; use warnings;). The regex uses a look behind and a look ahead assertion to anchor the capture group so that the replaced text is only the number. The /e then gets the calculation done in the substitution.


DWIM is Perl's answer to Gödel

In reply to Re: Manipulating a string in a tagged file by GrandFather
in thread Manipulating a string in a tagged file by rsriram

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.