#!/usr/bin/perl use strict; use warnings; my $dummy = ""; my $rollup = combine(""); my $oneline; while () { $rollup->($_); # once end is reached store it in a variable # reset variable-in-sub for next iteration if (/end;/) { # breaks if I remove $dummy and replace it with "" $oneline = $rollup->($dummy); $rollup = combine(""); print $oneline,$/; } } sub combine { my $concat = shift; return sub { chomp($_[0]); $concat .= $_[0]; return ($concat); } } #### __DATA__ line1; line2; line3; end; line4; line5; end; #### line1;line2;line3;end; line4;line5;end; #### Modification of a read-only value attempted at closure line 26, line 4.