> $text = qq| > This is text and it contains a couple of e-mail addresses, > like [EMAIL PROTECTED] and [EMAIL PROTECTED] what If I want to search > for these [EMAIL PROTECTED] etc etc addresses in the text > and perform search and replace function on those. > |; > Any idea as how to extract all the E-mails from the text > above and performing s/@/#/; on all addresses at the same > time? Just want to extract email addys and want to replace > @ with something un-readable by spam bots.
Hmm... just thinking on the fly... You could very simply match the email address, like so: $text =~ m/[EMAIL PROTECTED]/g; Label the matches to make replacement of the @s more targeted: $text =~ m/([A-Za-z0-9_\-\.]+)\@([A-Za-z0-9\-\.]+\.[A-Za-z]+)/g; So if an email address was say [EMAIL PROTECTED], the (brackets) would put 'keith' into $1 and 'szlamp.com' into $2. Then we'd simply find these matches again and replace the @ with #, this way it won't replace all @ symbols just those in the email address you've found, as @s may be used elsewhere in the plaintext. $text =~ tr|[EMAIL PROTECTED]|$1\#$2|; Then you want to do this on all the email addresses in the text, so compiling all the features you'd end up with something like this: while ( $text =~ m/([A-Za-z0-9_\-\.]+)\@([A-Za-z0-9\-\.]+\.[A-Za-z]+)/g ) { $text =~ tr|[EMAIL PROTECTED]|$1\#$2|; } So that should do it, I think, haven't debugged, but can't see any glaring errors, good luck, mail me if you need any more help. [keith szlamp.com]# -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]