fork download
  1. #!/usr/bin/perl
  2.  
  3. my $string = "
  4. BEGIN <<date>>
  5. <<something>
  6. BEGIN
  7. <<something>>
  8. END <<comment>>
  9. BEGIN <<time>>
  10. <<more somethings>>
  11. BEGIN(cause we can)END
  12. BEGINEND
  13. END
  14. <<something else>>
  15. END
  16. ";
  17. $string =~
  18. s/(?xs)
  19. (?(DEFINE)
  20. (?<pattern1>BEGIN)
  21. (?<pattern2>END)
  22. )
  23. (?&pattern1)
  24. (
  25. (?> (?# <-- "once only" search )
  26. (
  27. (?! (?&pattern1) | (?&pattern2)).
  28. )+
  29. )
  30. | (?R)
  31. )*
  32. (?&pattern2)
  33. /!!!!/;
  34. print "$string";
Success #stdin #stdout 0s 4596KB
stdin
Standard input is empty
stdout
!!!!