my $filename = "file.gif"; my $filepath = "/path/to/"; if(-e "$filepath$filename") { my $_binCheck = is_file_binary("$filepath$filename"); if($_binCheck && $_binCheck == 1) { # print header for download and then open the file in binary mode and print to window for the attachment } else { # print header for download and open the file normally and print to window for the attachment } } else { die "File does not exist: $filepath$filename"; }