#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; my $myfile = '/dir/subdir/infile1.txt'; open( my $in, '<', $myfile) or die "Can't open $myfile: $!"; map { chomp; $hash{ $_ }++ } ; close($in); print Dumper \%hash;