open my $fh, "<", $file1 or die "Couldn't open '$file1': $!"; while (my $record = <$fh>) { # ... } close $fh;