use strict; use warnings; my @recs = ("a11:b21:c34", "d32:e32:", ":g02:i6", "k92:l9:m22"); my @good_recs = grep { (split/:/,$_)[1] =~ /2/ } @recs;