in reply to using a subroutine
Perl is a great language, but sometimes the system utilities are a better tool, e.g. (untested):
find /lib -name 'core.*' -exec rm -f {} \;
In Section
Seekers of Perl Wisdom