my $aa = "Accepted and agreed to by Jerry Smith as of the 1st day of November 2005."; if ( $aa =~ m{ (?:as of)* (?:\s|\n)* #for any possible space or line end (?:this|the)* (?:\s|\n)* #for any possible space or line end ( (?:[1-31]) #day, 1 to 31 (?:st|nd|rd|th) #for all the cases like 1st, 2nd, 3rd, 25th (?:\s|\n)* #for any possible space or line end (?:day of)* (?:\s|\n)* #for any possible space or line end (?:January|February|March|April|May|June|July| August|September|October|November|December) (?:\s|\n)* #for any possible space or line end (?:\,|\s)* #for any possible space or comma end (?:\s|\n)* #for any possible space or line end ([1,2]\d{2,3}) #year ) (?:\,|\.|\s)* (?:[ ]{2}|\n|\z)* #Two spaces, newline, or string end }ixmsg) { print $1; }