@compare = ('^foo ', ' bar$'); $i=0; foreach (@compare){ unless $test =~ $compare[$i]){ print $test; $i++ } }