I agree with BillKSmith and ww.

but ...

use 5.010 ; use strict ; use warnings ; use Data::Dump qw( dump ) ; my @data = @{ _get_data() } ; my @clean_data ; my @removed_data ; foreach my $data_elem ( @data ) { # "Subject: 4 Details - MICHAEL4 NICHOLSON4 - **Senior S4* (4)", if( $data_elem =~ /^(.*?):(.*?)-(.*?)-.*?\*\*(.*?)\*.*?\((.*?)\)$/ + ) { my $subject = $1 ; my $item = $2 ; my $name = $3 ; my $position = $4 ; my $id = $5 ; unless( $subject eq 'Subject' ) { warn( "Subject not 'Subject', Ignoring ... \n" ) ; next ; } push @clean_data, [ $subject, $item, $name, $id ] ; push @removed_data, $position ; } else { warn( "Unknown data format - Ignoring\n" ) ; } } dump( \@data ) ; dump( \@clean_data ) ; dump( \@removed_data ) ; exit() ; sub _get_data { my @data ; foreach my $data_item ( 0 .. 10 ) { if( rand() < .5 ) { push @data, "Subject: $data_item Details - MICHAEL$data_item N +ICHOLSON$data_item - **Senior S$data_item* ($data_item)" ; } else { push @data, "NoSub: $data_item Details - MICHAEL$data_item N +ICHOLSON$data_item - **Senior S$data_item* ($data_item)" ; } } return \@data ; }
OUTPUT ( Note there is a 'rand' in there so you might not see this )
Subject not 'Subject', Ignoring ... Subject not 'Subject', Ignoring ... Subject not 'Subject', Ignoring ... Subject not 'Subject', Ignoring ... [ "NoSub: 0 Details - MICHAEL0 NICHOLSON0 - **Senior S0* (0)", "Subject: 1 Details - MICHAEL1 NICHOLSON1 - **Senior S1* (1)", "Subject: 2 Details - MICHAEL2 NICHOLSON2 - **Senior S2* (2)", "Subject: 3 Details - MICHAEL3 NICHOLSON3 - **Senior S3* (3)", "Subject: 4 Details - MICHAEL4 NICHOLSON4 - **Senior S4* (4)", "NoSub: 5 Details - MICHAEL5 NICHOLSON5 - **Senior S5* (5)", "NoSub: 6 Details - MICHAEL6 NICHOLSON6 - **Senior S6* (6)", "NoSub: 7 Details - MICHAEL7 NICHOLSON7 - **Senior S7* (7)", "Subject: 8 Details - MICHAEL8 NICHOLSON8 - **Senior S8* (8)", "Subject: 9 Details - MICHAEL9 NICHOLSON9 - **Senior S9* (9)", "Subject: 10 Details - MICHAEL10 NICHOLSON10 - **Senior S10* (10)", ] [ ["Subject", " 1 Details ", " MICHAEL1 NICHOLSON1 ", 1], ["Subject", " 2 Details ", " MICHAEL2 NICHOLSON2 ", 2], ["Subject", " 3 Details ", " MICHAEL3 NICHOLSON3 ", 3], ["Subject", " 4 Details ", " MICHAEL4 NICHOLSON4 ", 4], ["Subject", " 8 Details ", " MICHAEL8 NICHOLSON8 ", 8], ["Subject", " 9 Details ", " MICHAEL9 NICHOLSON9 ", 9], ["Subject", " 10 Details ", " MICHAEL10 NICHOLSON10 ", 10], ] [ "Senior S1", "Senior S2", "Senior S3", "Senior S4", "Senior S8", "Senior S9", "Senior S10", ]

In reply to Re: Regex Question by tmharish
in thread Regex Question by Anonymous Monk

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.