You really need to show the full code.
If you install my $ML inside the anonymous routine passed to Parallel::Loops , then you only set the value in the child process and the value will not be available to the parent.
It is not clear why you are using Matlab processes, but they will not be saved after the death of their parent, which is one of the child processes that are launched by your main program.
You can try declaring my @matlabs outside the loop, and then do
push @matlabs, Win32::OLE->new('Matlab.Application')
inside the loop. But if you have several persistent Matlab processes, then why not just run a simple for loop?
source share