#!/usr/bin/perl -w use strict; my @tests = ( 'I have 4 hamsters', '10', '11', 'I have 23 camels', 'Where is my wallaby?', '0', '1 1', ); foreach my $test (@tests) { if ($test =~ /(?:\D|^)([1-9]|10)(?:\D|$)/) { print "'$test' matches with the number $1\n"; } else { print "'$test' does not match\n"; } }