in reply to Why am I getting a Divide by Zero error?

$base_url =~ s!/[^/]*?$!!; #strip off the subdirectory
Why are you using *? here? The greedy quantifier would seem to do what you want. But there's a better choice. A regex is a little bit of overkill here; you might want to check out rindex on the perl manpages, or this site. Your second regex could use a little improving too, though its hard to say what exactly could be done without knowing what $address is holding; I had some advice, but I noticed the /g on the regex. That leads to the idea that there are many addresses there(and that you should be careful with .* then, unless they are separated by \n's).