in reply to syntax question
$fld0 = "abcX"; $fld0 = "abcX\n"; [download]
Another possibility uses substr, which will not match the \n:
if (substr($fld0, -1, 1) eq 'X') { next } [download]