sub gps { my $gps_device; while (1) { goto END if $die == 1; if ($gps_start == 1) { $gps_device = GPS::NMEA->new(Port => $gps, Baud => 4800) or die; my $timeout = 5; while (1){ #stops the warnings in the GPS device module local $^W = 0; print "before\n"; eval { local $SIG{ALRM} = sub {die "GPS Device has timed out\n"}; alarm $timeout; ($ns,$lat,$ew,$lon) = $gps_device->get_position; #warn $@ if $@; alarm 0; }; die if $@ && $@ ne "GPS Device has timed out\n"; if ($@){ print "WARNING\n"; } else{ print "nope\n"; } #($ns,$lat,$ew,$lon) = $gps_device->get_position; print "after\n"; print "$die\n"; goto END if $die == 1; last if $gps_start == 0; sleep 3; } undef $gps_device; } else {sleep 4} } END: }