in reply to if/else loop prints extra values

Whenever you print out the problem values, put some sort of marker around them so that you can see the whitespace: eg: print "\]$problem$\[ <-- this was bad!\n";

Also, note that "" is not a valid URL. You probably have some empty strings / blank lines in your input.