#!/usr/bin/perl use lib "/nss/nfx/thread_libs/lib/"; use threads; my $thr = threads->create( sub { while (1) { eval { while (1) { print "Starting Main function again.\n"; worker(); } }; if ($@) { print "Error Occured: <$@>.\n"; $@=(); sleep (5); } } } ); sub worker { open FILE_OUT, "> /root/xyz" or die "Can't open file: $!"; } while (1) { sleep 500; }