use strict; use warnings; use 5.010; while () { # skip separator lines next if /^----/; my @columns = split /\s*\|\s*/; # remove leading space $columns[0] =~ s/^\s+//; # now do something with @columns # you'll want to do something else here, not just # printing to the console say join ',', @columns; } __DATA__ ------|----------|--------|-------------------------|--------| S.No | TimeStamp| UE-Name| Test-Config | UL/DL | ------|----------|--------|-------------------------|--------| 1 | 18:24:38 | -NA- | Sanity_001_0001_10_00 | System | ------|----------|--------|-------------------------|--------| 2 | 18:31:34 | ueh1 | Sanity_002_0002_00_11 | UL | ------|----------|--------|-------------------------|--------| 3 | 18:23:48 | ueh1 | Sanity_003_0003_06_09 | UL | ------|----------|--------|-------------------------|--------| 3 | 18:23:48 | ueh1 | Sanity_003_0003_06_09 | DL | ------|----------|--------|-------------------------|--------| 4 | 18:38:30 | ueh1 | Sanity_004_0004_24_00 | DL | ------|----------|--------|-------------------------|--------| 5 | -NA- | -NA- | Sanity_001_0001_10_00 | System | ------|----------|--------|-------------------------|--------| 6 | 18:31:34 | ueh2 | Sanity_002_0002_00_11 | UL | ------|----------|--------|-------------------------|--------| 7 | 18:23:49 | ueh2 | Sanity_003_0003_06_09 | UL | ------|----------|--------|-------------------------|--------| 7 | 18:23:48 | ueh2 | Sanity_003_0003_06_09 | DL | ------|----------|--------|-------------------------|--------| 8 | 18:38:30 | ueh2 | Sanity_004_0004_24_00 | DL | ------|----------|--------|-------------------------|--------|