#!/usr/bin/perl -wl while () { chomp; print join ( '/', ( split ( '/', $_ ) )[ 3, 4 ] ); } exit; __DATA__ /mydirectory/directory/test/z2.htm /mydirectory/directory/other/testhere.htm /mydirectory/directory/test/dir/z6.htm