For example, to extract the day, month, year, time and minutes from a date-and-time entry (see before), you mays write:
#!/usr/local/bin/perl
print "Please enter date and time, as in \"08-OCT-1997 16:30\"\n";
my $entry = <STDIN>;
chop ($entry);
my ($day, $month, $year, $hour, $min) =
$entry =~ /(\d\d)-(\w\w\w)-(\d\d\d\d) (\d\d):(\d\d)/;
# here the "remembered" parts from the regular expression were directly
# assigned to a list of variables.
print "Month: $month\n";
$line =~ /ACM1_(HUMAN|RAT|MOUSE)/;and for grouping characters before a quantifier, e.g.
$seq =~ /(GATA){2,}/; # or
$seq =~ /(GATA)+/;
In both cases, the parentheses will also cause "remembering" of the substrings matched by the patterns enclosed by them.
$seq =~ /TT(GATA)*(\w*)/; # $1 will contain "GATA" # $2 will contain the rest of the sequence after the GATA repetitions.
To avoid "remembering" things in parentheses, write ?: before them. e.g.
$seq =~ /TT(?:GATA)*(\w*)/; # $1 will now contain the rest of the sequence after the GATA repetitions.
if ($seq =~ /(...).+\1/) { }