I must recommend that you look at perlre and perlvar. Specifically the performance hit associated with $& (last match). Also, using $' (text following last match) operator in a substitution doesn't make sense at all (unless your intention is to have everything after copyright appear twice within the resulting string). If you are just dealing with a string that contains "copyright 2003-2004" then please take arthas's advice and get to know the concatenation (.) operator. If you are looking to add ",2005" to "copyright 2003-2004" within a larger string then a substitution is a good solution, but yours isn't at all what you're looking for. When your string is "this is copyright 2003-2004 etc." the results will be "this is copyright 2003-2004 etc. ,2005 2003-2004 etc." Instead, you should use backreferences to determine what you ought to be inserting. For instance:

$_ = "I like the number 4 and I left my dog in the garage last night o +n accident"; # which I did...poor pup :-/ # store "number xx" where xx is a natural number as a # backreference and replace it with itself followed by # s/(?>number \d+)/ as well as the number 7/g; print $_,$/; __DATA__ output: I like the number 4 as well as the number 7 and I left my dog in the g +arage last night

Hope this helps.

UPDATED: Start to respond to a post that has one response that may be not what the OP is looking for, step away to get the dog out of the garage (again!), come back and finish the post, submit, and discover in your absence that two more replies have gone up :-/

antirice    
The first rule of Perl club is - use Perl
The
ith rule of Perl club is - follow rule i - 1 for i > 1


In reply to Re: appending to end of string by antirice
in thread appending to end of string by jc23

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.