my @array1; my @array2; my @args = ( [ \@array1, "foo", "file_1.gz"], [ \@array2, "bar", "file_2.gz"] ); foreach (@args) { &file_processing($args->[0], $args->[1], $args->[2]); } sub file_processing { my ($array_ref, $arg, $file) = @_; my $script = "/export/home/ssesar/Perl/another_script.pl"; open(FILE, $script . ' ' . $arg . ' ' . $file . ' |') or die ("can't do it: $!\n"); while () { chomp; push @{$array_ref}, $_ unless /^(?:\#|none|unknow)/i; } close FILE; }