use strict; use File::Spec::Functions; use File::Basename; my $file = 'test.txt'; my ($base,$path,$type) = fileparse($file, qr/\.txt/); print "base=$base path=$path type=$type\n"; print catfile($path, $base, '.xml'); # test\.xml #### print catfile($path, $base . '.xml');