in reply to Can't include a HEREDOC within RHS of a Regex

use strict; use warnings; my $data = "line1\nfoobar\nline3\n"; $data =~ s{(foo)(bar)}{ my $one = $1; my $two = $2; $one .= <<'END_TEX +T'; $one.$two; }e; Insert 1 Insert 2 END_TEXT print $data;
Works like a champ
Microsoft Windows XP [Version 5.1.2600] (C) Copyright 1985-2001 Microsoft Corp. C:\Documents and Settings\Neva>cd \code\Jff C:\code\JFF>perl regex.pl line1 foo Insert 1 Insert 2 bar line3

Replies are listed 'Best First'.
Re^2: Can't include a HEREDOC within RHS of a Regex
by 7stud (Deacon) on Jun 15, 2011 at 06:38 UTC

    ...and that syntax applied to the simpler version:

    use strict; use warnings; use 5.010; my $data = "greeting"; $data =~ s{greeting} {my $repl = <<"END_OF_STR"; "$repl goodbye mars"; }e; hello world END_OF_STR say $data; --output:-- hello world goodbye mars

      ...and that syntax applied to the simpler version:

      While your code is quite revealing, your explanation leaves to be desired. You seem to be saying the following snippets are equivalent:

      print "a", <<"END_OF_STR", "c"; b END_OF_STR
      print "a", <<"END_OF_STR", "c"; b END_OF_STR

      They're not.