use JSON qw/encode_json/; my $data = { auth => { "RAX-KSKEY:apiKeyCredentials" => { username => $USERNAME, apiKey => $API_KEY, }, }, }; my $json = encode_json($data);