By the way, wouldn't it be easier to give the data as parameter to swap.pl, i.e. system("swap.pl \"$_\" &")?
This would only work for non-binary data naturally and you would have to escape " \ and $ in the string.
Not only easier, but more robust. Those of us who have been burned in almost every possible way cringe at the assumption that
swap.pl will be done with the control file in less than one second, when it will be replaced by the control file for another instance.
If the control data is too complex to pass as an argument, then give each control file a different name and pass the name to
swap.pl as an argument.