[Solved] Perl: string manipulation – surrounding a word with a character ‘@’


Whenever you need some reasonably common matching problem resolve in Perl, you should always first check the Regexp::Common family on CPAN. In this case: Regexp::Common::Email::Address. From POD Synopsys:

  use Regexp::Common qw[Email::Address];
  use Email::Address;

  while (<>) {
      my (@found) = /($RE{Email}{Address})/g;
      my (@addrs) = map $_->address, Email::Address->parse("@found");
      print "X-Addresses: ", join(", ", @addrs), "\n";
  }

1

solved Perl: string manipulation – surrounding a word with a character ‘@’