Well if u already use your variable in the global scope, you should also define it in the global scope, not inside the function.
You can then simply include the php file where u define ur global variable (lets call it source script) into the script u wanna use, with a simple include
or require
statement before using it. I precisely work like this too in my plugin. However, make sure u prefix such globally used custom variables, by defining them like so:
$your_plugin_name_variable
To avoid naming conflicts with other wp-globals or other globals coming from other plugins.
If your global variable has a constant content, you could also define it inside a class as public static
variable. This is especially recommended if you would like to load several global variables / functions on different pages. They would then all be safely stored under the class name, and you don't need to worry about naming collisions for all of them (just make sure ur class name is unique though). You can then simply use them in your script without the need of instantiating a class object (that's why u may define them as public static).
If your global has a particular dynamic content for which the first method I explained is not suitable, consider storing it in a database in key value style. Then your source script would simply retrieve its value from the database, and you would then relate the retrieved value to your global variable's name, and include that source script wherever u use it, as in proposition 1.
I recommend u to use one of these solutions, I actually use all of them with my plugins in function of the respective complexity.
get_option()
if they're already saved as one option.