for each collection { $have-apple = 0; $have-orange = 0; $have-pear = 0; #examine about 30 items: for each item { if( $item eq "apple" ) { $have-apple = 1; } if( $item eq "orange" ) { $have-orange = 1; } if( $item eq "pear" ) { $have-pear = 1; } } # then, when all items examined unless( $have-apple ) { add apple; } unless( $have-orange ) { add orange; } unless( $have-pear ) { add pear; } }