in reply to match a word in an words' array

You should probably be using a hash in the first place. Try something like this:
sub addfor{ my ($mainwidget,$entryVariable) = @_; my %history; if (exists $history{$entryVariable}) { $mainwidget->messageBox (-icon => 'error', -type => 'OK', -title => 'Error for input', -message => "duplicate input"); } else { $widget{'forwardlistbox'}->insert ('end', $entryVariable); $history{$entryVariable} = 1; } }
Hashes are almost always the proper way to implement a set.

(Also, 'use strict;'! You've got some phantom variables floating around. I'm not sure whether $widget is the same as $mainwidget or not, and @history was unscoped.)