@list = split /(?=PATTERN)/;
####
my $pat = qr/^[ \t]*[^\s:]+:[ \t]*$/m; # allow leading/trailing ws
my $pat = qr/^[^\s:]+:/m;
$_ = slurp_file;
my @stanzas = split /(?=$pat)/o;
####
@list = /( .*? PATTERN | .+ )/gsx;
####
my $pat = qr/(?:^[ \t]*\n)+(?:[ \t]+\z)?/m;
$_ = slurp_file;
my @list = /( .*? $pat | .+ )/ogsx;
####
my @list = split /^\s*(?:\n|\z)/m;
shift @list if @list && $list[0] eq ""; # remove empty first element
####
my $delim = qr/^[ \t]*SOMETHING[ \t]*$/m;
my $pat = qr/$delim(?:\n[ \t]*)*(?:\n|\z)/o;
####
# Partition a string into paragraphs based on a
# pattern which matches the beginning of a paragraph.
sub partition_para_beg {
my ($pat, $str) = @_;
$str = $_ unless defined $str;
if ("" =~ /$pat/) {
require Carp;
Carp::croak("invalid pattern matches empty string: \"$pat\"\n");
}
split /(?=$pat)/;
}
# Partition a string into paragraphs based on a
# pattern which matches the end of a paragraph.
sub partition_para_end {
my ($pat, $str) = @_;
$str = $_ unless defined $str;
if ("" =~ /$pat/) {
require Carp;
Carp::croak("invalid pattern matches empty string: \"$pat\"\n");
}
return $str =~ /(.*?(?:$pat)|.+)/gs;
}