my %all_files; foreach my $file (@files) { open(my $fh, "<", $file); my @data = <$fh>; $all_files{$file} = \@data; close($fh); } #### foreach my $file (@files) { open(my $fh, "<", $file; my @data = <$fh>; close($fh); } #### { my @file; my $fh; foreach my $file (@files) { open($fh, "<", $file); @data = <$fh>; close($fh); undef $fh; # Frees $fh's content. undef @data; # Frees @data's content. } }