my $str ='/something/more words'; my @bits = $str =~ m!()/([^/]+)/([^/]+)()!; print $_,$/ for @bits; #### something more words
## something more words