$rrstring =~ s/^((?:[^\n";]+|"(?:[^\n"\\]|\\[^\n])*")*);[^\n]*$/$1/mg; ^ was missing #### # Here's the simplest case where it fails: # $expect = "\"Joe\""; # $rdata = $expect . " ; \"comment\""; $expect = "\"John \\\"The Wiz\\\" Doe; programmer\""; $rdata = $expect . " ; \"comment\""; print("Input: ", $rdata, $/); print("Expect: ", $expect, $/); if(($rdata)=~m[;]) { if(($rdata)=~m[^(".*")($|\s*;)]) { $rdata = $1; } else { ($rdata)=~s/;.*//g; } } print("Get: ", $rdata, $/); __END__ output ====== Input: "John \"The Wiz\" Doe; programmer" ; "comment" Expect: "John \"The Wiz\" Doe; programmer" Get: "John \"The Wiz\" Doe; programmer" ; "comment"