#!/usr/bin/perl use warnings; use strict; # The DATA filehandle is just a an open handle on the current # file. The current file is just the $0 variable (so long as # you haven't changed it) # main part of script ... my $count; while(){ $count = $_ ; print "$count\n";} $count++; # then redo the count update: rewrite_count($count); sub rewrite_count { my $count = shift; open(SELF,"+<$0")||die $!; while(){last if /^__END__/} truncate(SELF,tell SELF); print SELF $count; close SELF; } __END__ 1232