#! perl -w use strict; my $haystack = "abcdefghijklmnopqrstuvwxyz"; my @needles = qw(abc cde fgh ghi ijk pqr rst xyz); my $regex = '(' . join('|', @needles ) . ')'; print "Pre-compilation:", $regex,$/; $regex = qr/$regex/s; print "Post-compilation:", $regex, $/; $haystack =~ /$regex/g; if ($#-) { print "$#+ matches found", $/; for (1..$#+) { print "\$_ is $_, & \$1 is $1", $/; print "$haystack contains ${$_} at $-[$_]", $/; } } __END__ C:\test>test Pre-compilation:(abc|cde|fgh|ghi|ijk|pqr|rst|xyz) Post-compilation:(?s-xim:(abc|cde|fgh|ghi|ijk|pqr|rst|xyz)) 1 matches found $_ is 1, & $1 is abc Can't use string ("1") as a SCALAR ref while "strict refs" in use at C:\test\test.pl line 19. C:\test>