From the code, headers will only be sent if header_type is not "none", and when you call header_add(), you have to first make sure the header type is not "none" (i.e., "header" or "redirect"), which probably explains why the last of your code works becuase you set the header_type first. What bothers me a little bit is that CGI::Application::new() sets the header to "header" by default, are you doing something else that might change it to "none"?