my $mode = "0755"; my $localfile = "$uploaddir/$filename"; # open a new file and transfer bit by bit from what's in the buffer open( SAVED, ">>$localfile" ); while ( my $bytesread = read( $remotefile, my $buffer, 1024 ) ) { print SAVED $buffer; } close SAVED; chmod $mode, "$localfile"; # or die "can't chmod: $!";