my %commands = ( 'LS' => \&lsftp, 'DIR' => \&dirftp, 'GET' => \&getftp, 'PUT' => \&putftp, 'DEL' => \&delftp, 'SIZE' => \&sizeftp, ); [...] my $cmd = $commands{$type}; if(&$cmd($value1, $value2) == 1) { sleep $idletime; next; }