my %seen_subject; my @subjects_seen; ... # $s is a subject read from the excel file if (! $seen_subject{$s}++) { push(@subjects_seen, $s); } ...