PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system() , 'back ticks' , exec() and open() )
I would like to run another PERL-script from first one, not exiting from the first one (as by exec() ), not catching the STDOUT of the called script (as in the back tick processing,) but having it printed out, as in initial script (as it is by system() .)
I do not need the return status (as by system() ); but,

  • I would like to have the called script to set some variables, that will be accessible in the calling script (sure by the our @set_var; )

My attempt (that I am not able to make do what I need) is:

...
 if($condition) 
{  local $0 = 'script2.pl';
    local @ARGV = ('first-arg', 'second_arg');
    do script2.pl;
}
print "set array is: '@set_var'\n";
...

The 'script2' would have something like:

#!/usr/bin/perl
...
  print "having input parameters: '@ARGV'\n";
  ... # all script activities
  our @set_var = ($val1, $val2, $val3);
  exit 0;

The proble in my code is that the do ... command is executing on beginning of the first script run and not in the place, where it is prepared for it (by set local .. vars!)

I did try to use the eval "do script2.pl" :

  • now it is executed in the proper place, but it is not setting the @set_var into the first script process!

Is there any idea to do it as I would like to have it?
(I understand, that I can rewrite the script2.pl as a function and load it by require() and execute the function: that will do everything as I prefer it; but I would like to leave the second script as is to be executable from shell by itself, as it is now.)

Does anybody have an idea how to do my whim?

The solution to my question is the command
do EXPR;
, having as EXPR the script-2!

That way the script-2 will have defined in script-1 some variables;
it will process everything, printing on STDOUT what it should print (the script-2), and
it will set any variable that will be available in the script-1 after completing the script-2.

After finishing the script-2 control coming back to script-1

That is all I been looking for!

(Hmm, after review my question, surprizingly realizing that I have used the 'do ..'
How it happening that I have mislead myself to have it not enough, I am not sure!
--- My apologizes for all that mess!!!! )