use strict; use warnings; use Getopt::Std; my %switches; getopts('s:', \%switches); my @array = qw(the quick fox jumped over the lazy dog); ITEM: foreach my $item (@array) { my $seen; if ($switches{s}) { ($seen = $switches{s} eq $item) if (!$seen); next ITEM if (!$seen); } print "$item\n"; }