my @list = qw(54 55 20 21 22 25) # simplifed greatly :) my %hash; @hash{@list} = (1) x @list; while () { # assuming FILE has been opened previously my @row = split(/,/); # assuming comma separator if ($hash{$row[-1]}) { # process line } }