One pretty standard way is to just pass the file(s) on the command line and parse each file one after the next:
use strict;
use warnings;
use Getopt::Long;
GetOptions(
'id1=s' => \my $id1,
'id2=s' => \my $id2,
);
for my $file (@ARGV) {
open (my $filename, "<", $file) or die "Could not open $file, $!";
while (<$filename>){
while (/$id1/g && /$id2/g)
{
print "$file:$.\n";
}
}
close ($filename);
}
Called like:
script.pl --id1="test1|test2" --id2="test3|test4" file1.txt file2.txt
Regarding your glob problem, post a small sample of your input file so others can reproduce the issue.