$var =~ s#/aasd##; # remove '/aasd' $var =~ s#/[^/]+##; # remove a slash followed by any number of # non-slashes substr($var,0,5,'');# replace the first 5-char substr with '' $var = substr($var, 5, length($var)-5); # get a substring $var =~ m#/[^/]+(.*)# and $var = $2; # match what follows # after the non-slashes # and set it to $var