#!/usr/bin/perl use strict; use warnings; my @words; my $word; my $text; my $file = "test.txt"; open (DATA, "+<", $file) or die("Could not open file: ".$file.". $!\n"); sub add { print "I am in\n"; while( ) { chomp; @words = split(''); foreach $word (@words) { print "This is word: ".$word."\n"; $text = $word + 1; print "This is the new word: ".$text."\n"; } } } &add(); print DATA "".$text."\n"; close (DATA);