use 5.010; use strict; use warnings; my $Outcome; while () { my @Result = (); next unless $_ =~/\d+\schunk/; s/\s+/ /g; push @Result, $_."\n"; $Outcome = \@Result; print "@$Outcome"; } print "X\n"; #debug print "@$Outcome"; __DATA__ Free text. Free text. Blah Blah Blah Transaction XXX Apple 28 chunk Pear 140 chunk cherry 231 chunk potato 1 chunk Sincerely Yours