$ perl -wMstrict -le '"/foo/bar/baz/bat"=~/\/(.+)\//; print $1' foo/bar/baz $ perl -wMstrict -le '"/foo/bar/baz/bat"=~/\/(.+?)\//; print $1' foo