#!/usr/bin/perl use strict; use warnings; open my $fh1, "file1" or die "$!: file1"; my $fh2; my @file2; { local $/ = undef; open my $fh, "file2" or die "$!: file2"; $fh2 = $fh; @file2 = <$fh>; } close $fh2; # could have closed in the above block, but just illustrating a point about scope here while (<$fh1>) { print; print @file2; } close $fh1;