$ cat t.pl use strict; use warnings; for my $line () { # Unpack can pull out multiple fields from a string and also trim and/or # perform some simple conversions. # You do, however, have to count out your field sizes. my @u_flds = unpack "A52A24A*", $line; print "UNPACK: router: <$u_flds[0]>\n"; print "\ttype and IP: <$u_flds[1]>\n"; # substr can be useful, but you it's a little cumbersome for many fields. # For only a couple, though, it's not too bad. my $router = substr($line, 0, 52); my $route_and_IP = substr($line,52,24); print "SUBSTR: router: <$router>\n"; print "\ttype and IP: <$route_and_IP>\n"; # Split is good if you have consistent delimiters. If your delimiter occurs # in one or more of your fields, though, you may have to glue some together. my @s_flds = split /\s+/, $line; print "SPLIT: router: <$s_flds[0]>\n"; print "\ttype and IP: <$s_flds[1] $s_flds[2]>\n"; print "\n"; } __DATA__ /data/alcatel_ethernet_7750/routername1- static-route 1.1.1.1/30 next-hop 2.2.2.2 bfd-enable tag 624 /data/alcatel_ethernet_7750/routername2- static-route 1.1.1.3/30 next-hop 3.3.3.3 bfd-enable tag 624 /data/alcatel_ethernet_7750/routername3- static-route 1.1.1.2/30 next-hop 4.4.4.4 bfd-enable tag 628 $ perl t.pl UNPACK: router: type and IP: SUBSTR: router: type and IP: SPLIT: router: type and IP: UNPACK: router: type and IP: SUBSTR: router: type and IP: SPLIT: router: type and IP: UNPACK: router: type and IP: SUBSTR: router: type and IP: SPLIT: router: type and IP: