my $Line = "1243 That will efficiently match a nonempty group with matching parentheses two levels deep or less."; if ($Line =~ /^(?!.*\bgroup\b)(\d{4}) ([^.]+?[.\!\?])$/){ print "$1\n$2\n"; #Does not print } elsif ($Line =~ /^(?!.*\bgXroup\b)(\d{4}) ([^.]+?[.\!\?])$/){ print "$1\n$2\n"; #Prints }