A few points, your analysis of URLs is fragile; you certainly wonβt get relative links. Also, you do not check 100 links, except for 100 matches of the current URL, which almost certainly does not mean what you mean. Finally, I am not very familiar with LWP, so I will give an example using the Mojolicious toolkit.
It seems to work, maybe it will give you some ideas.
source share