my ($string, $string2) = ("./t2", "/some/path/to/t3"); print join "\n", map {(split /\//)[-1]} ($string, $string2); #### t2 t3