#!/usr/local/bin/perl -w $string = "/dir1/dir8/dir2"; $string =~ m|([^/]+)$|; print $1;