$format = &Check_Format($report); &Display_Report($format); sub Check_Format { my $report = $_[0]; my ($name,$format) = split(/\./,$report); return uc($format); } sub Display_Report { my $type = $_[0]; my ($offset,$bytes,$buffer,$contents,$print_pdf); if ($type eq 'XLS') { $print_xls = 'path/to/data/reports'; open(XLS, "$print_xls") || Write_Error($print_xls); $offset = 0; $contents = ''; binmode XLS; until(eof(XLS)) { $bytes += read(XLS,$buffer, 1048576, $offset); $offset += 1048576; $contents .= $buffer; } close XLS; print header(-type => 'application/vnd.ms-excel'); print $contents; } else { if ($type eq 'PDF') { $print_pdf = '/path/to/data/reports'; open(PDF, "$print_pdf") || Write_Error($print_pdf); $offset = 0; $contents = ''; binmode PDF; until(eof(PDF)) { $bytes += read(PDF,$buffer, 1048576, $offset); $offset += 1048576; $contents .= $buffer; } close PDF; print header(-type => 'application/pdf'); print $contents; }