my $file = "project.txt"; # Use three-argument form of open() (available in perl 5.6.0) # and check the return value. open(FILE, '<', $project) or die "Can't open $project: $!\n"; my %input; while(my $line = ) { chomp $line; # Get rid of whitespace (newline) at the end of the string if($line =~ /\tCM+(\d*)/io) { $input{$1}++; } } close(FILE);