in reply to compare two urls

As suggested by others, the URI module is a good place to start, but you are not being sufficiently explicit wrt the requirements. If you want an algorithm that claims that the following two URIs are identical:

http://www.xyz.com/

and

http://xyz.com/

Then please note that they are not guaranteed to point to the same web pages.