my @lines = ( "@attribute 'Sex' { Male, Female}", "@attribute 'Feature 0' real", "@attribute 'Feature 1' real", "@attribute 'Feature 2' real", "@attribute Malic_acid REAL", "@attribute Ash REAL" ); foreach my $line (@lines) { $line =~ /^@attribute\s+[']?(.*?)[']?\s+[{]?(.*?)[}]?$/; print "relation name: $1\n"; print "type: $2\n"; }