#!/usr/bin/perl use strict; use warnings; use File::Find; my %actions_hash = define_actions(); if (!defined @ARGV ) { @ARGV = "-h"; } my $action = shift; # First argument my @args = @ARGV; # Remaining arguments if (exists $actions_hash{$action}) { $actions_hash{$action}->(@args); } else { $actions_hash{_default_}->(@args); } sub define_actions { return ( '-f' => \&findfile, ); } sub findfile { my $target = $args[0]; my $location = "/tmp/dir1"; my $filename = find \&wanted, "$location"; sub wanted { (my $foundfile = $File::Find::name) if $File::Find::name =~ $target; return $foundfile; } print $filename; }