use warnings; use strict; open (my $fh, '<', "data.txt") or die "could not open dirs.log $!; while (my $line=<$fh>) { $key = lc($line); $Hash{$key}=$line; } open my $hash, '>', "hash.txt"; print $hash Dumper( \%Hash ); close $hash;