#! perl use strict; use warnings; my $len = 7; for my $s (' 999', ' 9999', '9999999', ' 9', ' 99 9', ' 9') { if (length $s == $len && $s =~ /^\s*\d+$/) { printf "%-*s matches\n", $len + 2, "|$s|"; } else { printf "%-*s does not match\n", $len + 2, "|$s|"; } } #### 12:33 >perl 960_SoPW.pl | 999| matches | 9999| matches |9999999| matches | 9| matches | 99 9| does not match | 9| does not match 12:33 >