use URI qw( ); for ( 'http://hostname.company.com:80//directory/...', 'http://hostname.company.com:80//', ) { my $url = URI->new($_); print $url->host, ":", $url->port, "\n"; print $url->path, "\n"; print "\n"; }