#!/usr/bin/perl -w #use strict; open (FF, "myfile.txt") ; if(!-e FF, "myfile.txt") { open FF, "> myfile.txt"; print FF "0\n"; close FF; } else { sub get_record { open (FF, "myfile.txt") or die "Cannot open file: $! "; chomp(my $record = ); close FF; return $record; } } $text = &get_record('pid.dat'); print "text = $text\n";