$ cat /tmp/x my $regex = '(2[0-4]|1?[0-9])?[0-9]|25[0-5]'; while (<>) { chomp; if ($_ =~ /^$regex$/) { print "$_ matched\n"; } else { print "$_ did not match\n"; } } $ perl /tmp/x 100 100 matched 200 200 matched 300 300 matched ^C