#!/usr/bin/perl

my $str = "Extract all words but word1 and word2.";
@list = ($str =~ m/\b(?!(?:word1|word2)\b)(\w+)/g);
print(join "\n", @list);
