in reply to Re: Replace $a with $b if $a ne $b
in thread Replace $a with $b if $a ne $b

Once you've cleared $dir, it's useless to compare $currentdir to it. Maybe you want something like:
my $printed_dir = ''; foreach $file (@filelist) { my ($dir, $name) = split '/', $file; printf("%s %s\n", ($dir eq $printed_dir ? '' : $dir), $name); $printed_dir = $dir; }

Caution: Contents may have been coded under pressure.