in reply to Testing for the presence of a hash key in a filename

my %list_of_keys = qw(DNI 1 SNI 1 JRN 1); my $filename = 'foo,JRN,SNI,bar'; my $regex = join('|', map { "\Q$_\E" } keys(%list_of_keys)); $regex = qr{\b($regex)\b}; # case insensitive? while($filename =~ /$regex/ig) { my $key = $1; print "Found key $key\n"; }
Also look at Regex::PreSuf which builds a better regex from a list of words.

Of course... if you always have a set delimeter you can do something like

my @values = split ',', $filename; for(@values) { print "Found key $_\n" if $list_of_keys{$_}; }
That is a better way to do it if you have something you can split on reliably

                - Ant
                - Some of my best work - (1 2 3)