in reply to Changing a variable to form submitted?
Do you ever define the %FORM hash? It looks like you're accessing the parameter values with CGI's param() method, so you probably want to set $basedir like this:
$basedir = $req->param('path');
BTW, indenting your code properly will make it much easier to read and maintain.