# Array declarations, use modules and initialization stuff for # both scripts go here sub get_list_of_foo { my @out_list; # the interesting part of your first script # in your loop { # Replace your print statement with something like: push @out_list, $mio2; # } return @out_list; } sub report_on_all_foos { # get the list on things we want to report my @input_list = @_; # Now we'll wrap your second script in a for loop so you # can do it for each match in the list previously # generated for my $match (@input_list) { # the interesting part of your second script goes here } } # Now, to put it together: report_on_all_foos( get_list_of_foos() );