Store tokens after splitting
1 answer
Place the capturing group inside your regex to keep the delimiter:
my $str = 'John|Mary/Matthew';
my @example = split /([\|\\\/])/, $str;
use Data::Dump;
dd @example;
Outputs:
("John", "|", "Mary", "/", "Matthew")
This is documented in the last paragraph: http://perldoc.perl.org/functions/split.html
+10
source to share