my @words = qw/ and or not one two three/; my %stop; $stop{$_}++ for @words; ... for my $w (split /\s+/, $line) { next unless length($w) > 2; next if $stop{$w}; ... $keys{$w}++; }