"does this mean writing another Perl script
with the main one calling another one that contains the
"system" command?"
Well....Sort of.....
If you want to put a timer on the system call, then ...........
The 'system' function will not return control of the running
script back to the script until the system call finishes.
Consequently, you need to be able to fork a child process to
go off and do the work, immediately returning control to
the parent process, and then mind the child process. If you
are new to Perl, then this might make your head swim a little.
The code below is a simple (maybe to simple) example of
forking two child processes. The first is used to try to do
some real work( in this case counting up to the value of
$duration). The second simply waits a period of time (5 sec)
and then tries to kill the previous child. The forking is
done with this syntax,
$pid = open(PIPE_NAME,"-|"

;
HuH? - That syntax spawns a child process and returns the
process ID of the child to the parent. In the child, $pid is
null. You end up with two nearly identical copies of the code
running at the same time. The only difference is the $pid var
which is populated in the parent and is null in the child.
STDOUT from the child goes back to the HANDLE in the parent.
You must 'exit' out of the child or it will continue right along
just like the parent.
Code:
#!/usr/local/bin/perl
unless ($duration = $ARGV[0]) { $duration = 8; }
# set autoflush to on to get immediate results from children.
$| = 1;
# fork a child to do the work
$pid = (open(ONE, "-|"));
# $pid exists - this is the parent process
if ($pid)
{
# spawn another process to kill the previous
# child if it lasts to long.
&spawn_timer($pid);
# Listen to the pipe from the first child for
# the results of what ever you asked it to do.
while (<ONE>) { print; }
}
$| = 0; # set AutoFlush back to its default.
# $pid is null
# this is a child process that needs to be timed/killed
if (!($pid))
{
for (1..$duration)
{
print "$_\n";
sleep(1);
# You would not want to sleep. Instead, you would
# want your system call here.
# system command, arg1, arg2;
}
# exit out here for child - you don't want it to
# continue with any code that might follow this
# if (!($pid)) block.
exit;
}
#----------------------------------------------------------
sub spawn_timer
{
# open/fork a child to time the previously opened child process.
$timer = (open(TIMER, "-|"));
# we now have three copies of the code running.
# we don't care if $time exists indicating a parent
# $timer is null - this must the child
if (!($timer))
{
sleep(5);
kill 1,$sibling;
exit;
}
}
This is very crude in the world of inter-process control(IPC).
The topic of IPC is beyond what can be dealt with here without
you first doing a little reading and playing. If you want to
get a little more sophisticated with this stuff you will need
to do some reading on SIGNALs, what they are, how to use them,
and such.
[I can't believe there is not a module that will make this
a little more straight forward.... but I have not gone looking,
yet.]
HTH
keep the rudder amid ship and beware the odd typo