my $last_maxsize = 170000; #I need to delete original files here... open my $last_in, '<', "$path_only/$file_name" or die $!; { local $/ = \$last_maxsize; while ( my $new_record = <$last_in> ) { next if -s $new_record > $last_maxsize; open my $last_out, '>', "$path_only/$file_name" or die $!; #It should create the file(s) with a new size print $last_out $new_record; close $last_out or die $!; } close $last_in; }