l.frankline offered an easy solution. Let me provide an overkill solution.

Many times the simple first solution you got turns to be a blocking stone when users change requirements and call for much more that they originally asked for. In the question, the Anonymous Monk is trying to achieve a replacement of the domain of an e-mail address and the solution he/she asked for was with regular expressions.

That can be done also (in a overkill fashion) with an e-mail address parsing module to achieve a much more general solution. For instance, here's one way to do it with Email::Address module:

use Email::Address; my $addresses = 'aaa@z.com bbb@z.com ccc@z.com "John Doe" <doe@z.com> +(John Doe) <j.d@z.com> '; my @emails = Email::Address->parse($addresses); for (@emails) { $_->address( $_->user . '@' . "something.com" ) if $_->host eq 'z. +com'; } my $new_addresses = join ' ', @emails;

This code is able to do the host replacement task not just in simple addresses like aaa@z.com but also "John Doe" <doe@z.com> and (John Doe) <j.d@z.com>. No hiccup with quoting, comments, and other eccentricities in e-mail addresses.


In reply to Re: replacing hosts in e-mail addresses by ferreira
in thread replacing email id using regex 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.