$z= $0; # store the name of the script in $z $z=~ s{.* # anything, greedy match / # then a / (the last one in $z as the match is greedy) }{}x; # removed