If you change the split regex to allow optional spaces around the hyphen and prepend and append hyphens to the text you can avoid the space trimming substitutions. You do have to shift away the empty first element though.
$ perl -le ' > $str = q{ this- is-aline - one- two }; > @arr = split m{\s*-\s*}, qq{-$str-}; > shift @arr; > print qq{->$_<-} for @arr;' ->this<- ->is<- ->aline<- ->one<- ->two<- $
I hope this is of interest.
Cheers,
JohnGG
In reply to Re^4: extracting names between symbols
by johngg
in thread extracting names between symbols
by aka_bk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |