#! perl -slw use strict; sub recurse { print ">> '${ $_[ 0 ] }'"; (my $depth=$_[1])--; if ($depth) { recurse( \ substr( ${ $_[ 0 ] }, 1, -1 ), $depth ); } else { ${$_[0]} = "XX"; } print "<< '${ $_[ 0 ] }'"; return; } my $str = 'abcdefghi'; recurse \$str, 3; print $str; recurse \$str, 2; print $str; __END__ >> 'abcdefghi' >> 'bcdefgh' >> 'cdefg' << 'XX' << 'bcdefgh' << 'abcdefghi' abcdefghi >> 'abcdefghi' >> 'bcdefgh' << 'XXi' << 'aXXi' aXXi