use strict;
my $str = '[1518-08-11 00:47] falls asleep
[1518-03-09 00:07] falls asleep
[1518-06-29 00:41] wakes up
[1518-05-27 23:58] Guard #743 begins shift
[1518-05-19 00:43] falls asleep
[1518-03-17 00:33] falls asleep
[1518-07-12 00:49] falls asleep
[1518-11-03 00:15] wakes up
[1518-06-05 00:57] wakes up
[1518-11-07 00:24] falls asleep
[1518-07-06 00:12] falls asleep
[1518-05-26 23:59] Guard #907 begins shift
[1518-06-01 00:28] wakes up
[1518-11-09 00:04] falls asleep
';
my $regex = qr/.(.*)(]\s)(.[a-zA-Z]*)(..)(.*)/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