use CGI; my $f; open (OUT,"somefile.pdf") or print STDERR "Can't open $!"; while () { $f .= $_; } close (OUT); my $l = length($f); print CGI->header( -type =>"application/octet-stream", -expires=> '+3d', -charset=>'utf-7', -Content_length => $l, -attachment => "example.pdf", ); print $f; exit;