#!/usr/bin/perl # http://perlmonks.org/?node_id=1206910 use strict; use warnings; use File::Find; $| = 1; my $dir = 'A'; find({preprocess => \&before, wanted => \&when, postprocess => \&after}, $dir); sub before { print "hi "; sort @_ } sub after { print "bye " } sub when { print "file! $File::Find::name " } #### file! A hi file! A/a1 file! A/a2 file! A/B hi file! A/B/b1 file! A/B/b2 bye file! A/C hi file! A/C/c1 file! A/C/c2 bye bye