while () { # $number will only get set if the current line contains one or more digits in between parentheses my ($number) = /\((\d+))/; # do something with $number }