http://qs321.pair.com?node_id=1233688


in reply to Re^2: processing file content as string vs array
in thread processing file content as string vs array

Yes, it looks to me like a simple while loop should be better. Here, I'm using the flip-flop operator to keep state:

use warnings; use strict; my @userinfo; while (<DATA>) { chomp; if ( /\@user_info_start/ ... /\@user_info_end/ ) { push @userinfo, $_; } } use Data::Dumper; print Dumper(\@userinfo); __DATA__ xxxxxxxxxxx xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : xxxxx xxxx*@Filetype : txt xxxx*@Version : 0001 xxxx*@Create_Date : 20190407 xxxx*@Product : xxxx xxxx*@user_info_end xxxxxxxxxxxxxxxxxxxxxxxxxxxx

Output:

$VAR1 = [ 'xxxx*@user_info_start', 'xxxx*@Title : Mr', 'xxxx*@Username : xxxxx', 'xxxx*@Filetype : txt', 'xxxx*@Version : 0001', 'xxxx*@Create_Date : 20190407', 'xxxx*@Product : xxxx', 'xxxx*@user_info_end' ];

And if you want to exclude the section markers, you can inspect the return value of the operator, for example:

if ( my $flag = /\@user_info_start/ ... /\@user_info_end/ ) { push @userinfo, $_ unless $flag==1 || $flag=~/E0/; }