foo( qr/ba[rz]|quux/ ); foo( 'ba[rz]|quux' ); sub foo { my $regex = shift; # //'s not necessary if $regex # was built with qr. return grep /$regex/ => @foo; }