Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The regular expressions for most pattern matches and substitutions are compiled into Perl’s internal form only once—at compile time, along with the rest of the surrounding statements. In the following example, Perl compiles the pattern /\bmagic_word\b/ only once, since it is a constant pattern. Perl reuses the compiled form again and again during run time:
# count occurrences of magic_word in @big_long_list
foreach (@big_long_list) {
$count += /\bmagic_word\b/;
}