#!/usr/bin/env perl use strict; use warnings; use autodie; { open(my $first_fh, "<", "file1.txt"); my @file1_lines = <$first_fh>; } { open(my $second_fh, "<", "file2.txt"); while (my $line = <$second_fh>) { my @data = my_sub($first_fh, $line); } } sub my_sub { 1 }