You should post the first lines of your program as:
#!/usr/bin/perl use strict; use warnings;
as they provide help to find errors in your code.

Maybe chomp: chomp(my @modules = `lsmod`); will eliminate the extra newlines.

The module Perl6::Form may be of help here although I've not used it, and there's a bit of documentation and I haven't read it all.

I tried something like this

#!/usr/bin/perl use strict; use warnings; use Perl6::Form; my @modules = <DATA>; for (@modules) { my ($tables, $count, $count2, $text) = split; print form "{<<<<<<<<<<} {>>>>>} {>>} {[[[[[[[[[[[[[[[[[[[[[[[[[[ +[[[[[[}", $tables, $count, $count2, $text; } __DATA__ ip_tables 9688 3 iptable_mangle,iptable_nat,iptable_fil +ter x_tables 8964 17 xt_CONNMARK,xt_length,xt_tcpudp,ipt_d +scp,ipt_ipp2p,xt_connmark,ipt_multiport,xt_state,ipt_TOS,xt_CLASSIFY, +ipt_ACCOUNT,ipt_MASQUERADE,ipt_REDIRECT,ipt_REJECT,ipt_LOG,iptable_na +t,ip_tables sch_htb 14464 0 sch_sfq 4992 0 ppp_async 8192 0 crc_ccitt 2048 1 ppp_async ppp_synctty 6912 0 ppp_generic 21140 2 ppp_async,ppp_synctty
Output is
C:\perlp>perl t2.pl ip_tables 9688 3 iptable_mangle,iptable_nat,iptabl- e_filter x_tables 8964 17 xt_CONNMARK,xt_length,xt_tcpudp,i- pt_dscp,ipt_ipp2p,xt_connmark,ipt- _multiport,xt_state,ipt_TOS,xt_CL- ASSIFY,ipt_ACCOUNT,ipt_MASQUERADE- ,ipt_REDIRECT,ipt_REJECT,ipt_LOG,- iptable_nat,ip_tables sch_htb 14464 0 sch_sfq 4992 0 ppp_async 8192 0 crc_ccitt 2048 1 ppp_async ppp_synctty 6912 0 ppp_generic 21140 2 ppp_async,ppp_synctty

In reply to Re: Formatting text, eg long lines by Cristoforo
in thread Formatting text, eg long lines by nanouk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.