in reply to Find Number in String then Ignore Characters proceeding

This should work. Change the "number of characters" as per your need.You need to modify the code as per your need

#!/usr/bin/perl use strict; use warnings; my $str = ".,a..A,,C..+4ACGTG.,-2TG,,...,a"; $str =~ s/[+-]?\d\w{4}//g; $str =~ s/[+-]?\d\w+//g; print $str;

Update 1: Eliya's method works awesomely well. I learnt something today. Thanks Eliya

Update 2: After several tries, I got this regex and it should also work

#!/usr/bin/perl use strict; use warnings; my $str = ".,a..A,,C..+4ACGTG.,-2TG,,...,a"; $str =~ s/[+|-](\d*)(\w*)/(substr $2, $1)/ge; print $str;

Replies are listed 'Best First'.
Re^2: Find Number in String then Ignore Characters proceeding
by BenPen95 (Initiate) on May 29, 2012 at 21:01 UTC

    The number after the + or - is the number of characters I would like to remove.

    If ..,+3AGCT.,. it should remove +3AGC but leaves the ..,T.,.