#!/usr/bin/perl #perl -e 'while (<>){print if (/^START/../^END/);}' input.txt use strict; my @array; open(my $fh, "<", "../temp/out2.asc") or die "Failed to open file: $!\n"; while(<$fh>) { if (/^START/../^END/){ chomp; push @array, $_; } } close $fh; print join " ", @array; print "\n";