$ perl -E 'my $c = reverse "/foo/bar/baz/bat"; say "matched ", scalar reverse ($1) if $c =~ m{(.+?)/};' matched bat