#!/usr/bin/perl -w use strict; my @texts = ('this is 110', 'cats have 9 lives', 'dogs have 4 legs', 'no numbers here', 'my uncle has 5 children and 17 grandchildren'); my @numbers = (1, 11, 5, 4, 67, 9, 45); # for efficiency, we turn all numbers into RegExes my @regex_num = map {qr /\D$_\D/} @numbers; my @matches = grep {my $txt=$_; grep {$txt =~ /$_/} @regex_num } @texts; print join "\n", @matches, "\n"; __END__ cats have 9 lives dogs have 4 legs my uncle has 5 children and 17 grandchildren