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;