use strict; use warnings; my $s = do {local $/, }; $s =~ s/\w+\s+\w+\s*\d+\s*\,(?:(?!(?:\n\n).)*)\n\n/'test'/egsi; #getting error #$s =~ s/\w+\s+\w+\s*\d+\s*\,.*?\n\n/'test'/egsi; #working fine print $s; output: ------- (?!(?:\n\n).)* matches null string many times in regex; marked by <-- HERE in m/ \w+\s+\w+\s*\d+\s*,(?:(?!(?:\n\n).)* <-- HERE )\n\n/ at pract.pl line 6. LMTRILOG db 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0; db 25 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0; __DATA__ LMTRILOG db 5 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0; db 25 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0;