Perl: How to convert xxx@dom.ain.com to domaincom

Hi,

Is there a way to convert xxx@dom.ain.com to domaincom, so to remove everything before and including @ and then to remove the dot from the rest of the line?

I know I can do:

$str = "xxx\@dom.ain.com";
print "String before: $str\n";
$str =~ s/.*?@//;
$str =~ s/\.//g; 
print "String after: $str\n";

Which outputs:

String before: xxx@dom.ain.com
String after: domaincom

But is there a way of combining the two operations into one?

Thanks!

Because the first substitution can only occur once, doing it with /g is harmless:

s/(.*?@|\.)//g

In the general case, mixing non-/g and /g substitutions isn't really possible, and extracting tokens between separators isn't really doable if you want to do some other substitution at the same time.

Thanks era!!! I tried probably everything else but left the brackets away :rolleyes:

Actually they aren't necessary. Good catch, or something ...

Samma p� finska?

If by brackets you mean () they are not even necessary:

$str = "xxx\@dom.ain.com";
print "String before: $str\n";
$str =~ s/[^@]*@|\.//g; 
print "String after: $str\n";

oops, sorry, we were posting at about the same time. Your post was not there when I read the thread. :o

Yep :slight_smile: Samma p� finska :smiley:

Thanks for both of you era and KevinADC!