This seems to work. :)
use strict;
use warnings;
use Data::Dumper;
use URI::Find;
my $data = do {local $/;<DATA>};
my $finder = URI::Find->new(
sub {
my($uri, $orig_uri) = @_;
return qq|<a href="$uri">$orig_uri</a>|;
}
);
$finder->find( \$data );
print $data;
__DATA__
Blah blah blah
Web: http://www.example.com
info.example.com
Web: http://info.example.com/
And another
Web site: http://another.example.com/ (doesn't always work)
Nice blog here: http://blog.example.com/niceblog/
UPDATE: change the inner sub to this to get exactly what you want:
sub {
my $u = URI->new( $_[0] );
return sprintf( '<a href="%s">%s%s</a>', $u, $u->host, $u->path );
}