in reply to replacing email id using regex

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.