#!/usr/bin/perl use warnings; use strict; my @fields = qw(Nachname Vorname Alter Hobbies); my $data = <<'END_HERE_1'; Müller;Jens;42;Fußball, Tennis, Vögel beobachten Knusper;Ronny;34;lesen, schlafen, langweilen END_HERE_1 my @data = split(/\n/, $data); sub getHashFromRecord { my $record = shift; my %h; my $i; my @s = split(/;/, $record); if ($#s != $#fields) { die "Wrong number of fields in record $record.\n"; } foreach $i (0 .. $#fields) { $h{$fields[$i]} = $s[$i]; } return %h; } my %h; my $i; my $record; print "Suchanfrage: "; my $q = ; chomp($q); foreach $record (@data) { %h = getHashFromRecord($record); if ($h{Nachname} eq $q) { print "\n"; foreach $i (@fields) { print "$i:\t$h{$i}\n"; } print "\n"; } }