my $test = construct_regex (@searcharray); my @results = grep { /$test/ } @longarray; sub construct_regex { my $regex = "^"; foreach my $subregex (@_){ $regex .= "(?=.*" . $subregex . ")"; } qr/$regex/; }