The split option fails if there's more than one '#' in the string - or if the '#' isn't followed by digits. Note that the regexp engine is optimized for patterns like /#[0-9]+$/:
perl -Mre=debug -e '$_ = "foobar#2"; s/#[0-9]+$//' Compiling REx "#[0-9]+$" Final program: 1: EXACT <#> (3) 3: PLUS (15) 4: ANYOF[0-9][] (0) 15: EOL (16) 16: END (0) anchored "#" at 0 floating ""$ at 2..2147483647 (checking anchored) mi +nlen 2 Guessing start of match in sv for REx "#[0-9]+$" against "foobar#2" Found anchored substr "#" at offset 6... Found floating substr ""$ at offset 8... Starting position does not contradict /^/m... Guessed: match at offset 6 Matching REx "#[0-9]+$" against "#2" 6 <foobar> <#2> | 1:EXACT <#>(3) 7 <foobar#> <2> | 3:PLUS(15) ANYOF[0-9][] can match 1 times out o +f 2147483647... 8 <foobar#2> <> | 15: EOL(16) 8 <foobar#2> <> | 16: END(0) Match successful! Freeing REx: "#[0-9]+$"
So, I'd go with the s/// solution.

In reply to Re^2: How do remove trailing data? by JavaFan
in thread How do remove trailing data? by Anonymous Monk

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.