open(FH,"file.exe"); binmode(FH); my $binary; while() { $binary .= $_; } close(FH); open(FH,">newfile"); print FH $binary; close(FH);