use strict; use warnings; my $regex_orig = qr{(?:^.* Electronic \s* Signature\(s\)\n)? (?:.* Signed \s* By:.* \n? (?:Date: \s* \S .*\n |Date:\n (?:\s* \S .*\n)+ )+ )+ (.*) (?:Entered \s* By:.*)?}xmi; my $regex_fixed = qr{(?:^.* Electronic \s* Signature\(s\)\n)? (?:.* Signed \s* By:.* \n? (?:Date: \s* \S .*\n |Date:\n )+ )+ (?:\s* \S .*\n)+ (?:Entered \s* By:.*)?}xmi; my $input_data = "Electronic Signature(s) Signed By: Date: Myself, Me 08/01/2014 12:18:41 PM Myself, Me 08/01/2014 12:18:42 PM Them Entered By: Myself, Me on 08/01/2014 8:44:43 AM"; my $input_data2 = "Electronic Signature(s) Signed By: Myself, Me Date: 08/01/2014 12:18:41 PM Signed By: Myself, Me Date: 08/01/2014 12:18:42 PM 7/31/2014 3:51:51 PM Version Signed By: Date: Myself, Me 7/31/2014 4:07:12 PM Myself, Me 7/31/2014 4:07:12 PM 7/31/2014 2:40:50 PM Version Signed By: Date: Myself, Me 7/31/2014 2:41:24 PM Entered By: Myself, Me on 08/01/2014 8:04:05 AM"; my $found; print "-- orig:\n"; if ($input_data2 =~ $regex_orig) { $found = substr($input_data2, $-[0], $+[0]-$-[0]); } print $found . "\n\n\n"; print "-- fixed:\n"; if ($input_data2 =~ $regex_fixed) { $found = substr($input_data2, $-[0], $+[0]-$-[0]); } print $found . "\n";