title: Extracting words starting with specific characters from a file, line by line, in Perl
body: <p>I'll start by saying I'm brand new to Perl and regex and I have never been best buddies.</p>
  
  <p>My problem is, I have a text file full of lines. Each line contains many 'words'. These words can contain letters, numbers, -, =, etc. Pretty much everything except white space. Each words is separated by white space.</p>
  
  <p>In every line there is one word that starts with three unique characters, 'mc='. So the word could be 'mc=abcde123', 'mc=12345hij', 'mc=blah'... you get my drift. I want to extract this word from each line and insert them into a new text file.</p>
  
  <pre><code>#!/usr/bin/perl
  
  use warnings;
  
  my $input = 'input.txt';
  my $output = 'output.txt';
  
  open (FILE, "&lt;", $input) or die "Can not open $input $!";
  open my $out, '&gt;' $output or die "Can not open $output $!";
  
  while (&lt;FILE&gt;){
      /(\s+mc=\/*S)/g;
      print $out $_;
  }
  </code></pre>
  
  <p>Not sure how much use any of this code will be to you. I'm well aware the regex is wrong- this just prints the entire content of input.txt into output.txt. Eventually I will be extracting additional values so If anyone could find it in their heart to help this poor, young, ignorant programmer out, I would be more than grateful!</p>