$line=~/- # negative (?: # followed by \d+(?:\.\d+)? # digits possible followed by '.' digits | # or \.\d+ # '.' digits )/x; # with out comments looks like this $line=~/-(?:\d+(?:\.\d+)|\.\d+)/