Chamara Keragala Chamara Keragala - 3 months ago 6
Perl Question

Remove the stuff up to and including the word in a string with multiple lines

I have the following string with multiple lines. I cannot make it one line since it is coming from a command output. for e.g:

my $myString = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also
the leap into electronic typesetting, remaining essentially unchanged.
It was popularised in the 1960s"


I want to strip off the stuff up to and including the word "scrambled"

I have tried below but does not seem to work.

if($myString =~ 's/.*(scrambled)//s')
{
print "Match: <$&>\n";
}

Answer
#!/usr/bin/perl
use strict;
use warnings;

my $myString = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. 
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a 
type specimen book. It has survived not only five centuries, but also 
the leap into electronic typesetting, remaining essentially unchanged. 
It was popularised in the 1960s";

$myString =~ s/.*scrambled//s;

print $myString;

Demo