#!/usr/bin/env perl use strict; use warnings; use Path::Tiny; use Data::Dump; ###### Output dhcp configuration file my $dhcpcdfile = 'd.conf'; print "at start of program---\n"; my @rows = path($dhcpcdfile)->lines; dd( @rows ); print "before loop---\n"; for my $line (@rows) { $line =~ s/^\s+//; # remove leading $line =~ s/\s+$//; # and trailing whitespace next unless length $line; # ignore empty lines next if $line =~ /^#/; # ignore comment lines my @fields = split /=/, $line, 2; dd( @fields ); } print "after loop---\n"; #### #IP Configuration #Fri Aug 27 16:07:40 NZST 2021 routers=192.130.1.1 interface=eth0 domain_name_servers=8.8.8. 8.8.1.1 ip_address=192.130.1.10/24 #### at start of program--- ( "#IP Configuration\n", "#Fri Aug 27 16:07:40 NZST 2021\n", "\n", "routers=192.130.1.1\n", "interface=eth0\n", "domain_name_servers=8.8.8. 8.8.1.1\n", "ip_address=192.130.1.10/24\n", ) before loop--- ("routers", "192.130.1.1") ("interface", "eth0") ("domain_name_servers", "8.8.8. 8.8.1.1") ("ip_address", "192.130.1.10/24") after loop---