You need the module to be imported before the rest of the file is parsed, so you need to use a BEGIN block. (A normal use, without the eval, implicitly creates its own BEGIN block.)
BEGIN {
$desired_module = ...
eval "use $desired_module";
}
...
function_from_desired_module; # should be OK now.