in reply to how do i get the 2nd line when the 1st is matched

One way is to treat both lines as one... ($match) = $text =~ /whatever_you_already_have\s*(\S+)/s

Replies are listed 'Best First'.
Re^2: how do i get the 2nd line when the 1st is matched
by Aristotle (Chancellor) on Aug 17, 2004 at 08:56 UTC

    Are you sure that pattern is what you want? It demands that the string be followed by any amount of whitespace (including none!), followed by at least one character of non-whitespace which will be capture. Here are some things it will match:

    $text = "whatever_you_already_havefoobar\n"; # $1 eq "foobar" $text = "whatever_you_already_have foo\nbar"; # $1 eq "foo" $text = "whatever_you_already_have\nfoobar"; # $1 eq "foobar" $text = "whatever_you_already_have\nfoo bar"; # $1 eq "foo"

    You probably meant something more along the lines of

    /whatever_you_already_have.*\n(.*)/

    Or if you want to do it using /s for other reasons,

    /whatever_you_already_have[^\n]*\n([^\n]*)/s

    Makeshifts last the longest.

      Aye, the solution can be adapted to more complex input if required. Thanks for expanding on it.