Update upload.pl

Refactoring - probably not syntactially sound yet...