use strict; use warnings; my %numbers = ( '2345678923' => 1, '2121212121' => 1, '4424352424' => 1, '2323232323' => 1 ); while () { chomp; if (//) { if (/(?:^|\D)(\d+)(?:\D|$)/ && exists $numbers{$_}) { print "$_\n"; } } } __DATA__ 2345678923 1 junk 12345678923 2121212121