my @ary = qw ( 1, foo, 2, bar5, 33 ); for ( @ary ) { #print only the numbers: print if /^\d+$/ }