Hi. Please put your code fragments between <code>...</code> tags. Then, your RE becomes $var=~s#\b(\d(?:[a-z]{1})?\-?\d(?:[a-z]{1})?)\b#'<t>'.$1.'</t>'#ges;. Note that the [..] becomes a link when used outside code sections.

From what you describe, I guess you want to do a match only, but your code fragment tells something different (substitution). I guess you want to match the text after the first comma (maybe without the surrounding whitespaces?), so you could try

#... # alt1: match only, leave $var unmodified: my $var = "sclerosing 1954, 5–7, 54, 59f-60d, 90, 114"; if ( $var =~ /^[^,]+,\s*(.+?)\s*$/ ) { print "Match: ==>$1<==\n"; # ==>5–7, 54, 59f-60d, 90, 114<== } # alt2: add <t>markup</t>, substitute $var2: my $var2 = "sclerosing 1954, 5–7, 54, 59f-60d, 90, 114"; if ( $var2 =~ s{^([^,]+,\s*)(.+?)(\s*)$}{$1<t>$2</t>$3} ) { print "Markup: ==>$var2<==\n"; # ==>sclerosing 1954, <t>5–7, 54, 59f-60d, 90, 114</t><== } #...
Hi i tried the below but it's cating the number 1954.
Here, your code fragment returns: 5–7, <t>54</t>, <t>59f</t>-<t>60d</t>, <t>90</t>, 114 ???

It is hard to guess what you really want, so if the explanation above doesn't help, please explain your problem more clearly. E.g. by providing examples of what your input is and what output you expect (a few lines each within <code>..</code> tags).

BTW: You don't need the e-modifier. Instead of s{(pattern)}{'<t>'.$1.'</t>'}e a simple s{(pattern)}{<t>$1</t>} would be sufficient.


In reply to Re^3: To Match the text by Perlbotics
in thread To Match the text by amexmythili

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.