在perl中正则表达式中的OR条件

pra*_*ant 3 regex perl if-statement

我正在尝试编写一个脚本,它通过Perl中的正则表达式执行OR函数.我编写了一个代码,其中如果字符串包含'D'或'E'后跟'P',则应打印"D或E后跟P",否则"D或E后面跟不是P".假设我给$ s ='ABCDEABCDEPABCDEAB'它应该打印else条件,但我认为我的if语句不能正常工作.请帮忙.

my $s = 'ABCDEABCDEPABCDEAB';
if ($s =~ /D|E(?=P)/) {
    print "D or E is followed by P";
} 
else {
    print "D or E is not followed by P";
}
Run Code Online (Sandbox Code Playgroud)

Roh*_*ain 8

if ($s =~ /[DE]P/) {
    print "D or E is followed by P";
}
else {
    print "neither D nor E is followed by P";
}
Run Code Online (Sandbox Code Playgroud)