You can create a user-defined script that performs any task you wish. These are often called from the output expression of a field or from another script.
How you call a user-defined script and what is passed to it depends on the script language you use. See the Script Languages topic for details.