my %item_count; %item_count{$_}++ for grep {/pattern/} @array @result = grep {$item_count{$_} <= 1} @array;