### No reason to do this, since you could just use the filename in the "open" call directly. my $executable = "C:/Users/Desktop/file.exe"; ### This won't work - that "-w" is extraneous and a syntax error. Furthermore, you have a conceptual problem: ### the way you're doing it here (if it worked) would OVERWRITE your program instead of ### executing it. open(-w EXECUTABLE,">$executable") or die "Can't open output file $executable\n"; while() { print EXECUTABLE "Something"; } close EXECUTABLE;