my $copyright = qr{\b copyright (?:ed)? \b }xi; my $date = qr{\b (?:19|20) \d\d \b }x; if ($str =~ s/$copyright.{0,200}$date|$date.{0,200}$copyright/) {...}