^(?:1()|2()|3())/sometext/sometext/(?:\1first|\2second|\3third)$
^(?:1()|2()|3())/sometext/sometext/(?(1)first)(?(2)second)(?(3)third)$
условные подмаски^(?:1(/sometext/sometext/)first|2(?1)second|3(?1)third)$
рекурсивные подмаски \номер_группы
#^(1|2|3)/sometext/sometext/(\1a)$#
$_='1/sometext/sometext/first';
s/^(1|2|3|.*)(.*)(\/.*?)$/($1==1?"$2\/first":""|$1==2?"$2\/second":""|$1==3?"$2\/third":"")=~"\/sometext\/sometext$3"?1:0/e;
print;
/
, иначе регулярка не отработает как надо.