use strict;
my $str = '#0
$dumpvars
0!
0"
0#
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 7
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 6
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 5
b0000000000000000 $
bxxxxxxxxxxxxxxxx /
bxxxxxxxxxxxxxxxx .
bxxxxxxxxxxxxxxxx )
b0111111111111111 %
bxxxxxxxxxxxxxxxx 1
bxxxxxxxxxxxxxxxx 0
bxxxxxxxxxxxxxxxx *
b10101010101010101010101010101010 &
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ,
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 2
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 3
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 4
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (
bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \'
$end
#600
1!
b0000000000000000 )
b0111111111111111 *
b10101010101010101010101010101010 +
b0000000000000000 /
b0111111111111111 1
b00000000000000000000000000000000 5
b10101010101010101010101010101010 4
b00000000000000000000000000000000 2
b00000000000000000000000000000000 3
b010101010101010101010101010101010 7
#1200
b0000010001010111 $
b0111101110101000 %
b10101100101001110100001001010001 &
0!
b10101010101010101010101010101010 ,
b00000000000000000000000000000000 -
#1800
1!
b0000010001010111 )
b0111101110101000 *
b10101100101001110100001001010001 +
b010101010101010101010101010101010 (
b010101010101010101010101010101010 \'
b0000010001010111 /
b00000010001010110111101110101001 5
b0111101110101000 1
b00000010000110001010011000011000 5
b10101100101001110100001001010001 4
b010101100101001110100001001010001 7
b00000010000110001010011000011000 2
b00000010000110001010011000011000 3
b010101110101111111110100001101001 7
#2400
b0000100010101110 $
b0111011101010001 %
b10101110101000111101100111111000 &
0!
b10101100101001110100001001010001 ,
b00000010000110001010011000011000 -
#3000
1!
b0000100010101110 )
b0111011101010001 *
b10101110101000111101100111111000 +
b010101110101111111110100001101001 (
b010101110101111111110100001101001 \'
b0000100010101110 /
b00000100001100010100110000110000 5
b0111011101010001 1
b00000100000010111010000100001110 5
b10101110101000111101100111111000 4
b010110000101111001000000000010000 7
b00000100000010111010000100001110 2
b00000100000010111010000100001110 3
b010110010101011110111101100000110 7
#3600
b0000110100000101 $
b0111001011111010 %
b10110000101000000111000110011111 &
0!
b10101110101000111101100111111000 ,
b00000100000010111010000100001110 -
#4200';
my $regex = qr/(?s)(\#\d{1,})(.*?)(\#\d{1,})/mp;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html