in reply to syntax question

Keep in mind that the regular expression $ matches an optional \n, so these two will match:
$fld0 = "abcX"; $fld0 = "abcX\n";

Another possibility uses substr, which will not match the \n:

if (substr($fld0, -1, 1) eq 'X') { next }