$line = " This is the test line"; $* = 'line'; # prepare Perl for treating 'line' @${*} = grep { !m!\s! } split //, reverse (''.$${*}); shift @{$*} while @{$*} > $[ +1; print $line[-1], " is the first character.\n";