В Perl есть несколько способов сделать это (TMTOWTDI):
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my $str='Here\'s a (good, bad, ..., ?) example to be used in this "reg-ex" test.';
# NB: grepping on $_ will remove empty results
my @matches = grep { $_ } split(/
\s* # discard possible leading whitespace
(
\.{3} # ellipsis (must come before punct)
|
\w+\-\w+ # hyphenated words
|
\w+\'(?:\w+)? # compound words
|
\w+ # other words
|
[[:punct:]] # other punctuation chars
)
/x,$str);
print Dumper(\@matches);
напечатает:
$VAR1 = [
'Here\'s',
'a',
'(',
'good',
',',
'bad',
',',
'...',
',',
'?',
')',
'example',
'to',
'be',
'used',
'in',
'this',
'"',
'reg-ex',
'"',
'test',
'.'
];