in reply to Trim Two Characters On Line

Here is exactly what you request.
substr( $line, -2, 2, '' ) if $line =~ /sum/;

You may want to remove the second and third last character, leaving a newline at the end.

substr( $line, -3, 2, '' ) if $line =~ /sum/;
Bill

Replies are listed 'Best First'.
Re^2: Trim Two Characters On Line
by jalopez453 (Acolyte) on Oct 23, 2020 at 16:24 UTC
    Thank you Bill. This was the perfect one liner for what I was looking for, but I ended up running into another problem, after running the process on all my files, come to find out, not all of them have the extra commas at the end as I expected. Would it be okay to send you a message and show you what I am trying to do.
      not all of them have the extra commas at the end

      Are you trying to read a CSV file? Better use Text::CSV (and its accelerator Text::CSV_XS), it can handle all of the evil edge cases that you didn't even think of.

      Would it be okay to send you a message and show you what I am trying to do.

      Perlmonks does not work that way. Post detail questions right here in this thread.

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        Not all please do... This is what I decide to do instead, but what is happening is it is wrapping the line after on the same line.
        while(<IN>) { my $line = $_; my $number = () = $line =~ /\,/gi; $line =~ substr( $line, -2, 2, '' ) if ($number > 79); print OUT "$line"; } close OUT; close IN; }