#!/usr/bin/perl use strict; use warnings; my $fileName = "version.txt"; my $fileDest = "version_modified.txt"; die "Problème d'ouverture du fichier $fileName" unless open(my $fh, '<', $fileName); die "Problème de création du fichier $fileDest" unless open(my $fd, '>', $fileDest); my $tot = 0; my $tot2 = 0; sub hostname; sub hostname{ print $fd $_; while (<$fh>){ if ($_ =~ /^hostname /){ hostname; }else{ # print $_; $tot2++; } } $tot++; } while(<$fh>){ hostname if ($_ =~ /^hostname /); } print $tot."\n"; print $tot2."\n"; close $fh; close $fd;