use grep instead of foreach