You can’t use SSI to send HTTP headers; by the time the SSI runs, it is too late.
You should approach the problem from the opposite direction and have Perl generate the whole page (using PSGI), preferably using a template language (such as Text::Xslate), possibly using a MVC framework (such as Dancer).
2
solved how to include perl script in html