in reply to Regular expressions and Arrays

Depending on the tests you might not need an array in lieu of alternation. And thus I present two other ways of solving your example:

1.

use strict; use warnings; while ( <DATA> ) { if ( /(^foo.*bar$)|(^foo)|(bar$)/ ){ print $1 ? "BOTH FOO AND BAR: $_" : $2 ? "ONLY FOO: $_" : "ONLY BAR: $_"; } else { print "NOT EITHER: $_" } } __DATA__ foo baz foo bar bar fu bar fuz foo on you bar
2.
use strict; use warnings; while ( <DATA> ) { /(^foo.*bar$)(?{print "BOTH FOUND: $_"}) | (^foo) (?{print "FOO FOUND: $_"}) | (bar$) (?{print "BAR FOUND: $_"})/x } __DATA__ foo baz foo bar bar fu bar fuz foo on you bar

-enlil