my @allFruit = qw/apple apricot banana coconut/; my @someFruit = map { if ($_ =~ m/^[ap]/) { $_;} } @allFruit; print "no. of some fruit: " . scalar(@someFruit) . "\n"; print "some fruit: " . join('*',@someFruit) . "\n";