use strict; use warnings; my $info = {}; while (my $line = <>) { my ($row_id, $book_id, $chapter, $section) = split /\t/, $line; if (defined $info->{$book_id}{$chapter}{$section}) { die "$book_id, $chapter, $section, line $."; } else { $info->{$book_id}{$chapter}{$section}++; } }