if ($_ =~ /\something(.*)somethingelse/i){ if (($1 >= 1) and ($1 <= 75)) { $a = $1; if ($a =~ /^\d+$/){ ... } } }