$text='Learning Perl? http://www.perlmonks.org/ is the place'; $text =~ s!(http://\S+) (\s+<([^>]+)>)? ! defined($3)? qq($3): qq($1) !gex; print $text;