in reply to Check last character of a string

How about testing and adding in one step?
$x =~ s/([^\\])$/$1\\/

Replies are listed 'Best First'.
Re^2: Check last character of a string
by Anonymous Monk on Aug 06, 2008 at 15:46 UTC
    Or without a capture:

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