use warnings; use strict; my $in = 'Simpletestxy'; my $tr_ed = $in; $tr_ed =~ tr/A-Za-z1-9/1-9a-zA-Z/; #complicate and add chars to the tr/// as you wish # 0 1 2 3 4 5 6 7 8 9 10 11 my $out = join '',(split '',$tr_ed)[qw(5 6 4 2 9 10 3 7 11 1 8 0)]; my $back = join '',(split '',$out )[qw(11 9 3 6 2 0 1 7 10 4 5 8)]; $back =~ tr/1-9a-zA-Z/A-Za-z1-9/; print "in=$in, tr_ed=$tr_ed, out=$out, back=$back\n";