There are a number of problems with your code, but the info you need to answer your question is already in the $url var. You simply need to extract the required portion of the url and add that to your print statement.

Use the URI::Split module to parse the url to extract the portion you need.