my $file = 'file.txt'; # open for input is default and now our die tells us which # file we were trying to open open (DATA, $file) or die "Can't open $file $!\n"; # assuming you aren't using @DATA for something else later # there is no need to slurp it all into memory now while () { next unless $. > 21; chomp; my @temp=(); foreach (split /,/){ s/"//g; # strip the quotes first if you want s/\s+$//; # to remove trailing whitespace push @temp, $_; } $compHash{$temp[0]} = $temp[1]; $aliasHash{$temp[2]} = $temp[3]; # you did mean $var4? } close (DATA);