use File::Basename; use Cwd 'abs_path'; # ... for (@files) { my ($name, $path)=fileparse $_; chdir abs_path $path; do { Something::with($name) }; }