On Thu, 31 Mar 2005 02:08:22 -0800, John W. Krahn wrote: > > $ perl -le' > my $str = q/[EMAIL PROTECTED]/; > $str =~ s/([EMAIL PROTECTED])/($a = $1) =~ tr|_|.|; $a/e; > print $str; > ' > [EMAIL PROTECTED] > > $ perl -le' > my $str = q/[EMAIL PROTECTED]/; > substr( $str, index $str, q/@/ ) =~ tr/_/./; > print $str; > ' > [EMAIL PROTECTED] >
Nice! Here are 2 other methods, just for the heck of it :-) # Method 1 my $str = '[EMAIL PROTECTED]'; my ($part1,$part2) = split /@/, $str; $part2 =~ s/_/./g; $str = $part1."@".$part2; print "$str\n"; # Method 2 my $str = '[EMAIL PROTECTED]'; while ($str =~ m/(?<=@).+?_/) { $str =~ s/(?<=@)(.+?)_/$1./; } print "$str\n"; Ram, there is just one thing you should notice - in your question, you double-quote the string you assign to $str. You can't do that, because the perl tries to evaluate the @lmn_p_q part as the name of an array. So you either have to single quote the string (as John and I did) or escape the @ sign with a backslash: my $str = "[EMAIL PROTECTED]"; Hope this helps, -- Offer Kaye -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>