in reply to Downloading file

Corion, CountZero and Anonymous Monk are all correct about turining on binmode for input stream and STDOUT. The following is how I would do something similar, it uses the File::Basename to extract the basename from a given path, open and read the file using IO::File, and output compliant header using CGI.

use strict; use warnings; use File::Basename; use IO::File; use CGI; binmode STDOUT; my $target_file = "/path/to/target_file.dat"; my $f = new IO::File "$target_file", "r" or die; my $file = do { local $/; binmode $f; <$f> }; my $cgi = new CGI; print $cgi->header( -type => 'application/x-unknown', -attachment => basename($target_file) ), $file;