Perl : How to remove a substring from a string

ambuli
ambuli used Ask the Experts™
on
Hi Experts,

I have to print the portion of a string by removing anything before the word teststring in the following string.

this is: a long line teststring:  this portion is needed

I want to print the new string as: this portion is needed.
Thank you
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2005
Commented:
Assuming the string is held as $value

$value =~ s/(.*?teststring)//;
print $value;
More efficient would be:

$value =~ s/^.*?teststring//;

as there is no reason to capture the string being removed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial