use File::Find; find(sub { $_ =~ /\.b\z/ && unlink $_ }, '/path/to/directory' );