use warnings; use strict; while () { process_record ($_) if /\@user_info_start/; } sub process_record #include first and last line { my $start_of_record = shift; my @userinfo; push @userinfo, $start_of_record; my $line; do { $line =; push @userinfo, $line; } until $line =~ /\@user_info_end/; print @userinfo; print "\n"; } =Prints 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 xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end =cut __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 d987sd66bd xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end somebus here or blank lines? whatever xxxxxxxxxxxxxxxxxxxxxxxxxxxx #### use warnings; use strict; while () { process_record() if /\@user_info_start/; } sub process_record { my $line; print $line while (defined ($line =) and $line !~ /\@user_info_end/); print "\n"; } =Prints xxxx*@Title : Mr xxxx*@Username : xxxxx xxxx*@Filetype : txt xxxx*@Version : 0001 xxxx*@Create_Date : 20190407 xxxx*@Product : xxxx xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx =cut __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 d987sd66bd xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end somebus here or blank lines? whatever xxxxxxxxxxxxxxxxxxxxxxxxxxxx #### use warnings; use strict; while () { process_record ($_) if /\@user_info_start/; } sub process_record #include first and last line { my $start_of_record = shift; print $start_of_record; my $line; do { $line =; print $line; } until $line =~ /\@user_info_end/; print "\n"; } =Prints 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 xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end =cut __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 d987sd66bd xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end somebus here or blank lines? whatever xxxxxxxxxxxxxxxxxxxxxxxxxxxx #### use warnings; use strict; while () { process_record ($_) if /\@user_info_start/; } sub process_record # include first and last line { my $start_of_record = shift; print $start_of_record; my $line; # a bit of strangeness caused by using handle while (defined ($line=) and $line !~ /\@user_info_end/) { print $line; } print $line; #the last line of record print "\n"; } =Prints 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 xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end =cut __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 d987sd66bd xxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxx xxxx*@user_info_start xxxx*@Title : Mr xxxx*@Username : yy xxxx*@Filetype : txt xxxx*@Version : 0005 xxxx*@Create_Date : 43 xxxx*@Product : xxxx xxxx*@user_info_end somebus here or blank lines? whatever xxxxxxxxxxxxxxxxxxxxxxxxxxxx