$matched = undef; for($index=0,$index<11;$index+=2) { if(substr($test_string;$index,2) eq "ab") { $matched = 1; last; } }