#!/usr/lib/perl # be good boy and always do following use strict; use warnings; # you don't have to use other HTTP modules because # LWP::UserAgent uses them itself use LWP::UserAgent; use HTTP::Request::Common; use HTTP::Cookies; my $ua = LWP::UserAgent->new; # this method call creates cookie jar object and tells # LWP::UserAgent object to use it automatically. You do not # have to call extract_cookies or add_cookie_headers # yourself $ua->cookie_jar(HTTP::Cookies->new(file => 'cookie_jar', autosave =>1); # configure LWP::UserAgent to follow redirects after POST push @{ $ua->requests_redirectable }, 'POST'; # first POST request - no need to handle redirects youself. # Let LWP handle them automatically. This is why I use # 'request' instead of 'simple_request'. $ua->request(POST "http://www.sitedomain.com/logi +n.cfm", { username =>'abcuser', userpass =>'abc123', submit =>'Submit' }); # Second POST request - same as in your code my $request = $ua->request(POST "http://www.sitedomain.com/page.cfm", { firstname =>"Michael", lastname =>"Jensen", company =>"companyname", address =>"111 East 222 South", city =>"Provo", state =>"UT", zip =>"99999" }); print $request->is_success ? "worked\n" : "failed\n";