while (<>) { if ( m/^header/ ) { (my $output = "." . $_ . <>) =~ s/\n[+]/ /; print $output; last; } }