#!/usr/bin/perl -w use strict; my %locations; foreach my $path (split(/:/,$ENV{PATH})) { opendir(DIR,$path) || die "Directory $path in your PATH can not be opened:$!\n"; foreach my $file (readdir(DIR)) { next if -d "$path/$file"; # not sure if this is really needed... next unless -x _; push (@{$locations{$file}},$path); } } foreach my $file (sort keys %locations) { print "$file :",join(" ",@{$locations{$file}}),"\n" if scalar($#{$locations{$file}}); }