12 if (/swap position (\d+) with position (\d+)/) {
13 (substr($data, $1, 1), substr($data, $2, 1))
14 = (substr($data, $2, 1), substr($data, $1, 1));
15 } elsif (/swap letter (\w) with letter (\w)/) {
16 eval "\$data =~ y/$1$2/$2$1/";
17 } elsif (/rotate left (\d+) /) {
19 $data =~ s/^(.{$n})(.*)/$2$1/;
20 } elsif (/rotate right (\d+) /) {
22 $data =~ s/^(.*)(.{$n})/$2$1/;
23 } elsif (/rotate based on position of letter (\w)/) {
25 my ($pref) = $data =~ /^(.*$l)/;
26 my $pos = length($pref);
28 $pos -= length($data) if $pos >= length($data);
29 $data =~ s/^(.*)(.{$pos})/$2$1/ if $pos;
30 } elsif (/reverse positions (\d+) through (\d+)/) {
31 substr($data, $1, $2-$1+1) = join('', reverse split //,
32 substr($data, $1, $2-$1+1));
33 } elsif (/move position (\d+) to position (\d+)/) {
34 my $l = substr($data, $1, 1);
35 substr($data, $1, 1) = '';
36 substr($data, $2, 0) = $l;
38 die "Unknown command $_.";