open(my $first_fh, "<", "file1.txt") or die "Cannot open \"file1.txt\": $!."; open(my $second_fh, "<", "file2.txt") or die "Cannot open \"file2.txt\": $!."; my @file1_lines = <$first_fh>; close $first_fh; while (my $line = <$second_fh>) { my @data = my_sub($first_fh, $line); # copy/paste error, should have passed $second_fh here # and of course a bunch of non-relevant stuff here }