Update upload.pl

Extract subroutines out to separate module for tidiness