use strict; use warnings; use feature qw{ say }; my $str = q{1234}; my $ref = \ substr $str, 1, 2; show(); noRefReset( $_ ) for qw{ a xyz }; $str = q{56789}; show(); noRefReset( $_ ) for qw{ pq ghijkl st }; say q{-} x 18; $str = q{1234}; $ref = \ substr $str, 1, 2; show(); refReset( $_ ) for qw{ a xyz }; $str = q{56789}; show(); refReset( $_ ) for qw{ pq ghijkl st }; sub noRefReset { ${ $ref } = shift; show(); } sub refReset { ${ $ref } = shift; $ref = \ substr $str, 1, 2; show(); } sub show { printf qq{%-9s - %s\n}, $str, ${ $ref }; }