in reply to Trim Two Characters On Line

 $line =~ s/(SUM.*)(..)/$1/

should meet your requirement.

Bonus: $2 will hold the truncated characters.

Demo in the debugger

DB<1> $_ = 'abcSUMcdexx' DB<2> s/(SUM.*)(..)/$1/ DB<3> p abcSUMcde DB<3> $_ = 'abcSUXcdexx' DB<4> s/(SUM.*)(..)/$1/ DB<5> p abcSUXcdexx DB<5>

Update: typo fixed in DB<1> , thx to AnomalousMonk for spotting.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^2: Trim Two Characters On Line
by AnomalousMonk (Bishop) on Oct 23, 2020 at 04:26 UTC

    $line =~ s/(SUM.*)(..)/$1/
    This does not seem to meet jalopez453's requirement. The strings 'SUMx' and 'SUM' both contain the substring 'SUM' and so should truncate to 'SU' and 'S' respectively, but do not.

    Also, I don't understand how the sequence of operations

    DB<1> $_ = 'abcSUXcdexx' DB<2> s/(SUM.*)(..)/$1/ DB<3> p abcSUMcde
    comes about. A typo?


    Give a man a fish:  <%-{-{-{-<

      Oh, I get your point. But that's how I understood the question.

      The OP should clarify.

      But you're right the pseudo code says otherwise.

      > A typo?

      Kind of, a side effect of the default page editing/cursor mode when I use the perldb inside emacs.

      Thanks fixed! :)

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery