http://www.perlmonks.org?node_id=691368


in reply to Improve perlfaq5: How can I translate tildes (~) in a filename?

Something like this would probably do it (I haven't actually tested it)
require File::HomeDir; $filename =~ s/^~(\w+)/File::HomeDir->users_home("$1")/e; $filename =~ s/^~/File::HomeDir->my_home/e;