sub DIRUtil { my $self = shift; my $caller; $caller = shift if ref $_[0]; my ($path, $dirname, $option) = @_; while ($option eq "-c") { print $path."\n"; chdir($path) or next; mkdir ("xxx") or next; return; } continue { # failure handling $caller->() if $caller; return; } }