Regex to find two strings in either order

I would like to determine if both the strings 'abc' and 'xyz', in either order, occur in $text.  The following works, but I have that feeling that there must be a better way.

 $text =~ m/abc.*xyz|xyz.*abc/

Is there a better way to do this than with alternation?
rexswainAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
ozoConnect With a Mentor Commented:
$text =~ /(?=.*abc).*xyz/s;
0
 
CmdrRickHunterCommented:
how about using logic and two regular expressions? ($text =~ m/abc/ && text =~ m/xyz).  Perhaps more parenthesis are needed.

It may look slower, but remember that simple regular expressions are usually much faster to find than ones with lots of wierd backtracking and long matches.
0
All Courses

From novice to tech pro — start learning today.