while() { print "$'", if($_ =~ /(.*)\//g); } __DATA__ ./t2 /some/path/to/t3 /some/t2