#converting String to Array $x = 'A-GTG-ACGT-'; @xArray = split('',$x); $gaps=0; foreach $ch (@xArray) { if ($ch eq '-') { $gaps = $gaps + 1; } } print $x," has ", $gaps," gaps.\n"; exit;