#!/usr/bin/perl use strict; use warnings; ## simulate actual files ## my $SI_txt =<) { next unless $_ =~ /\d/; #throw away header line or blank push @SIarray, $_; } while (<$SI2>) { print; if (/^\s*Atom\s+QA/) #interleave first line of SI.txt { print shift @SIarray; } } print @SIarray; __END__ Molecule 01-Carbon-Energy.log Energy: -37.7131454546 Geometry: Atom Atomic No. x y z 1 6 0.000000 0.000000 0.000000 Atom QA DA(alpha) DA(beta) DA(total) 1 1.0000 2.2238 2.6173 2.3812 Molecule 02-Methanide-Geometry.log Energy: -39.6946868929 Geometry: Atom Atomic No. x y z 1 6 0.000000 0.000000 0.000000 2 1 0.000000 1.084453 0.000000 3 1 -0.939164 -0.542227 0.000000 4 1 0.939164 -0.542227 0.000000 Atom QA DA(alpha) DA(beta) DA(total) 1 1.3294 1.9996 1.9996 1.9996 2 -0.1098 2.2233 2.2233 2.2233 3 -0.1098 2.2233 2.2233 2.2233 4 -0.1098 2.2233 2.2233 2.2233