sub authenticate { # Create a request my $req = HTTP::Request->new( POST => 'https://identity.api.rackspacecloud.com/v2.0/tokens' ); $req->content_type('application/json'); #my $json = '{"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":"foo", "apiKey":"00000000000000000000000000000000"}}}'; my $json = quotemeta( {"auth":{"RAX-KSKEY:apiKeyCredentials":{"username":$USERNAME, "apiKey":$API_KEY}}} ); $req->content( $json ); # Pass request to the user agent and get a response back my $res = $ua->request($req); # Check the outcome of the response if ( $res->is_success ) { # Do stuff ... } else { print $res->status_line, "\n"; } }