#!/usr/bin/perl use strict; use warnings; use Device::SerialPort; my $comm; sub foo { $comm=0; } $comm=new Device::SerialPort('/dev/ttyS0') or die "Error opening device\n";