my $tests = [ 'Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:22' ]; # Put the regex you want to test in here. foreach my $test (@$tests) { if($test =~ qr/^(?:Nov 29 [^\n]*\n)*\z/s) { print "$test\n REGEX MATCHED\n"; } else { print "$test\n FAILED!\n"; } } Nov 29 16:01:27 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:28 Nov 29 16:01:22 FAILED!