I doubt my solution is generic enough for you, although it matches the data supplied and so might form a starting point. sub table() is included to make the output a bit more readable.

use feature ":5.14"; use warnings FATAL => qw(all); use strict; sub table($;$$) # Table formatter {my ($d, $c, $w) = @_; # Data, control, width my @D; for my $e(@$d) {for my $D(0..$#$e) {my $a = $D[$D] // $w->[$D] // 0; my $b = length($e->[$D]); $D[$D] = ($a > $b ? $a : $b); } } my @t; for my $e(@$d) {my $t = ''; for my $D(0..$#$e) {if (substr(($c//'').('L'x($D+1)), $D, 1) =~ /L/i) {$t .= substr($e->[$D].(' 'x$D[$D]), 0, $D[$D])." "; } else {$t .= substr((' 'x$D[$D]).$e->[$D], -$D[$D])." "; } } push @t, $t; } @t } my @t = ([qw(name version release arch)]); for(split /\n/, << 'END') # Parse sample data fipscheck-1.2.0-1.el5.x86_64 iptables-ipv6-1.3.5-5.3.el5_4.1.x86_64 libXi-1.0.1-4.el5_4.i386 perl-Carp-Clan-5.3-1.2.1.noarch rpm-build-4.6.1-2.el5.x86_64 END {my ($name) = (split /\./)[0] =~ s/..\Z//r; my ($version) = /-([\d\.]+)/; my ($release) = /.*-(.*)\./; my $arch = (split /\./)[-1]; push @t, [$name, $version, $release, $arch]; } say for table([@t]); # Format data

Produces

name            version  release      arch    
fipscheck       1.2.0    1.el5        x86_64  
iptables-ipv6   1.3.5    5.3.el5_4.1  x86_64  
libXi           1.0.1    4.el5_4      i386    
perl-Carp-Clan  5.3      1.2.1        noarch  
rpm-build       4.6.1    2.el5        x86_64 

In reply to Re: regex for rpm: name, version, release, arch by philiprbrenan
in thread regex for rpm: name, version, release, arch by mhearse

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.