#!/usr/bin/perl use strict; use warnings; sub mygrep (&@) { my $code = shift; my @result; foreach $_ (@_) { push(@result, $_) if &$code; } @result; } print join "\n", mygrep { /a/ } qw(cat hat bed den);