' tom harry ' =~ m/(?<=tom).*(dick|harry|john)/ && print(1, $/); # 1 ' harry tom ' =~ m/(?<=tom).*(dick|harry|john)/ && print(2, $/); # (nothing)