use File::Spec::Functions qw( abs2rel ); print( abs2rel('A:\\B.CD(E)~!@#$%^&\\E\\F.txt', 'A:\\B.CD(E)~!@#$%^&'), "\n" );