Um, it's still not clear what you're actually trying to accomplish. There are a handful of odd properties in this snippet of code, including some things that look like mistakes or misconceptions. As many others here would tell you, things would actually go better for you with "use strict;"
First, I would assume that your declarations at the top were intended to look like this:
@res = qw/index.cgi/; # could be more than one file...
@ext = qw/css tmp class edf/;
$regex = ''; # note: "$", not "@"
Next, since you don't initialize "$reg" to anything prior to the first "for" loop, it comes out starting with "|", which is "grammatical", but probably won't do what you want -- try this:
perl -e '$_ = "hi"; print "ok\n" if ( /|x/ );
It will always print "ok", no matter what string is assigned to $_, because a regex that starts with "|" will always match anything (even an empty string). (update: I realize that $reg gets appended to some other literal when it's finally used for matching something; having "|" at the start will still not do what you probably expect/want it to do.)
BTW, the more legible idiom for concatenating values onto a string inside a loop is:
$string = "initial value";
for ( @addons ) {
$string .= " $_"; # or whatever
}
Next, it's not clear why you have the "if ($regex)" condition, since this variable is apparently empty (false) when you reach this point.
Finally, the last line is a complete mystery. What does "$thing" contain, and what are you really hoping to match? It looks like you are now trying to use $reg as a reference to a scalar (because of the two dollar-signs); again, this is "grammatical", but $reg is not a reference to a scalar, so you end up with an empty string at that point in the regex.
Take a few steps back from the minute details, and try to approach it from "the big picture". What is the situation that you are starting with, and what do you want it to be when your code does its job properly?
If you're just trying to build a regex that will match a given set of file name extensions (e.g. qw/css tmp class edf/), all you need to do is:
my $ext_regex = '\.(' . join('|', qw/css tmp class edf/) . ')$';
for ( @filenames ) {
print "this one matches: $_\n" if ( /$ext_regex/i );
}
|