$check = substr($string_to_match, -17, 17); if ($check=~/A{14,17}/) {print "correct";}