use Path::Class qw/file dir/; my $startdir = dir('/Y/Music/'); my $curdir = dir('/Y/Music/Schubert/Lieder/Terfel'); my $plsname = join('_', grep {length} $curdir->relative($startdir)->components).".pls"; print "$plsname\n"; __END__ Schubert_Lieder_Terfel.pls