#!/usr/bin/perl use strict; use warnings; use Cwd; my $command = shift; apply( @ARGV ); # takes a directory to start in, and a command # to apply recursively sub apply { my $curdir = cwd; my ( $dir, $command ) = @_; return unless chdir $dir; system $command; if ( not opendir DIR, '.' ) { chdir $curdir; return; } my @children = grep { -d && !/^\.\.?$/ } readdir DIR; closedir DIR; for my $child ( @children ) { apply( $command, $child ); } chdir $curdir; }