Many ways to do this in Perl. One is to use regular expressions:
if ($data =~ /^\[([^\]]+)\]\s*\[([^\]]+)\]\s*\[([^\]]+)\]/) {
my $command = $1;
my $source = $2;
my $destination = $3;
}
else {
die "Didn't match\n";
}
It's a bit ugly. Basically \[ and \] matches your square brackets. You have to prefix them with a backslash because brackets are magical in regular expressions. The [^\]] matches non-closing brackets. The [^x] means anything but x. The plus sign on the end means at least one. Thus [^\]]+ matches as many characters as it can until it comes to another closing bracket. The curved parentheses around the expression saves it in the $1, $2, and $3 variables. I repeat this for each item I'm matching.
There's a way of looping through a regular expression to keep finding matching parts, but that's a little more complicated than you want to get into right now.
Another is to use the split command:
$data =~ s/^\[(.*)\]$/$1/;
my ($move, $source, $destination) = split (/\]\s*\[/, $data);
The first line removes the prefixing and appending brackets, and then I split on the "] [" brackets. Again, I'm using regular expressions.
Regular expressions are the life blood of Perl, and you should learn about them as much as you can. Perl takes the standard Unix regular expressions, and expands them quite a bit. You can type in perldoc perlre to find documentation about regular expressions and how they're used, but it's more of a reference manual and not a tutorial. You can also try perldoc perlrequick which is more of a tutorial.
substrfunction