first, make sure you use strict; in your code. Adding that and doing perl -c immediately finds $resp->content-type -- it should be $response->content_type (also $resp->status_line should be $response->status_line; and one of the while/$token loops needs a 'my')
Also, using WWW::Mechanize might simplify things for you ...
/me goes off to look at actual code now to try to answer primary question ..