perl -le '$patt = shift; print qr/$patt/' 'a\Ubc' # prints (?-xism:a\Ubc) perl -le '$patt = shift; print qr/$patt/' 'a\\Ubc' # prints (?-xism:a\\Ubc)