use URI::URL (); my $url = URI::URL->new($url_as_string) or warn "URL error"; print $url->port