in reply to displaying excel/pdf files in browser

Well, I don't know if this is the whole problem, but you're doing a lot of unnecessary work. If you want to read a complete file into a scalar, then print it, you can do it all in one go:

binmode XLS; { print header(-type => 'application/vnd.ms-excel'); local $/; print <XLS>; close XLS; }
The same applies to your PDF file.

HTH