in reply to Get text between start and end tag
Or if you don't wish to read the whole file into memory, you can always just read in a section:
#!/usr/bin/perl use strict; use warnings; my %res; { # for localizing $/ local $/ = 'END_TAG'; /BEGIN_TAG_(\d+)(.*)END_TAG/s and $res{$1} = $2 while <DATA>; } use Data::Dump 'dd'; dd \%res; __DATA__ Any text is in this document. But I'm only interested in the text between a beginning and an end tag +. BEGIN_TAG_110 In this text I'm interested in. It can consist of several lines. Until the end tag. END_TAG and any other things I'm not interested in until the next begi +nning tag starts. Any other text. BEGIN_TAG_237 I need this text. END_TAG More text ...
Outputs:
{ 110 => "\nIn this text I'm interested in.\nIt can consist of several + lines. Until the end tag.\n", 237 => "\nI need this text.\n", }
|
|---|