use 5.010; use strict; use warnings; my @urls = qw< https://www.abc.com/ap/ap/top-news/76/nTk3M/ https://www.abc.com/videos/news/eye-catching/vmxJr https://www.abc.com/ap/top/45/state-political-news/fgdfgd https://www.abc.com/ap/ap/top-news/ https://www.abc.com/ >; for (@urls) { m{ ^ https://www\.abc\.com/ # correct stem (?: .+? / ){3} # non-greedy string then slash x 3 .+ # at least one other character }x ? say("MATCH: $_") : say("NOT: $_") }