@terms = ("Word1","Word2","Word3"); $match = $1 if join (" ", @terms) =~ /((?:^| )$lineFromSomeTextFile(?: |$))/;