in reply to Re: Check last character of a string
in thread Check last character of a string

Or without a capture:

perl -wMstrict -le "for (@ARGV) { print; s{ (?<! \\) $ }'\\'xms; print } " with\ sans with\ with\ sans sans\