$ perl -e "use Path::Tiny; print path( q{ro/sham/bo} )->basename " $ perl -Mre=debug -e " $_ = q{ro/sham/bo} ; print m{/([^/]+?)$} " Compiling REx "/([^/]+?)$" Final program: 1: EXACT (3) 3: OPEN1 (5) 5: MINMOD (6) 6: PLUS (18) 7: ANYOF[\x00-.0-\xff][{unicode_all}] (0) 18: CLOSE1 (20) 20: EOL (21) 21: END (0) anchored "/" at 0 floating ""$ at 2..2147483647 (checking anchored) minlen 2 Guessing start of match in sv for REx "/([^/]+?)$" against "ro/sham/bo" Found anchored substr "/" at offset 2... Found floating substr ""$ at offset 10... Starting position does not contradict /^/m... Guessed: match at offset 2 Matching REx "/([^/]+?)$" against "/sham/bo" 2 | 1:EXACT (3) 3 | 3:OPEN1(5) 3 | 5:MINMOD(6) 3 | 6:PLUS(18) ANYOF[\x00-.0-\xff][{unicode_all}] can match 1 times out of 1... 4 | 18: CLOSE1(20) 4 | 20: EOL(21) failed... ANYOF[\x00-.0-\xff][{unicode_all}] can match 1 times out of 1... 5 | 18: CLOSE1(20) 5 | 20: EOL(21) failed... ANYOF[\x00-.0-\xff][{unicode_all}] can match 1 times out of 1... 6 | 18: CLOSE1(20) 6 | 20: EOL(21) failed... ANYOF[\x00-.0-\xff][{unicode_all}] can match 1 times out of 1... 7 | 18: CLOSE1(20) 7 | 20: EOL(21) failed... ANYOF[\x00-.0-\xff][{unicode_all}] can match 0 times out of 1... failed... 7 | 1:EXACT (3) 8 | 3:OPEN1(5) 8 | 5:MINMOD(6) 8 | 6:PLUS(18) ANYOF[\x00-.0-\xff][{unicode_all}] can match 1 times out of 1... 9 | 18: CLOSE1(20) 9 | 20: EOL(21) failed... ANYOF[\x00-.0-\xff][{unicode_all}] can match 1 times out of 1... 10 <> | 18: CLOSE1(20) 10 <> | 20: EOL(21) 10 <> | 21: END(0) Match successful! boFreeing REx: "/([^/]+?)$" $