use strict; use warnings; my @strings = ('foo 1 bar', '1 foo bar', 'foo bar 1'); for my $string (@strings) { print "$string\n" if $string =~ /\D0*([1234]?\d|5[0123])\D/gc; }