my @aFruits = qw(apple bananna orange pear); #declare a variable for the grep result my @aSelected; #define your condition my $sCondition = q{/^b/ || /^p/}; #construct the grep command and evaluate it my $sEval = "\@aSelected = grep($sCondition,\@aFruits)"; eval $sEval; #see the results print "selected fruits (eval): " . join(',', @aSelected) . "\n";