I don't know the source of the problem with your script and can't say if the problem resides in $_ because I don't see where any value is assigned to $_ or $delim. What I can do is try to fix my script so it won't reject blank input.
What I suspect happened when you tested my script: your file of regex patterns may have included a blank record (just an extra carriage-return/line-feed character would do it) which resulted in an element containing a string made up of whitespace characters or nothing at all being included in the array I use to build the $pattern. I can fix that by removing any zero-length elements from the array before building the pattern. Please try the following:
#!/usr/bin/perl
use strict;
use warnings;
#You can open a file and read from it.
#Here I read from my <DATA> handle for convenience.
#The point is, you want your regex patterns stored
#in an array.
my @arr = <DATA>;
foreach (@arr){
s/^\s+//;#Remove leading whitespace
s/\s+$//;#Remove trailing whitespace
$_ = quotemeta($_); #Escape characters such as $, ., etc,
}
@arr = grep(length($_) > 0, @arr); #Weed out all zero-length elements
my $pattern = '(' . join('|', @arr) . ')';
#Now let's say you read two input records from <STDIN> (not shown here)
#and assign them to $input1 and $input2
my $input1 = "GET / HTTP/1.0";
my $input2 = "Windows NT 5.2; en-US; rv:1.9.1.6; Major 3.0)";
my $input3 = "\t \n"; #Input can be all …