my %Y; while (<>) { ... my ($y) = ... ; next unless $y; if(@ARGV) { foreach (@ARGV) { $Y{$y}++,next if $y eq $_; } } else { $Y{$y}++ } }