if (can_send($file)) { # we assume you can program whatever rules you need here open(INP,"<$file") || die "Can not open $file:$!\n"; # but handle that in can_send my MIME::Types $types = MIME::Types->new; my $mime = $types->mimeTypeOf($file) || "application/octet-stream"; print header("Content-type: $mime"); binmode(INP); binmode(STDOUT); while () { print $_; } close(INP); }