use strict; use File::Spec; my $str = " /home/madam ~/madam"; my @strarray = split(" ",$str); for (@strarray){ if ( -d $_){ print "path present : $_\n"; } else { print "path not present : $_\n"; } }