#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @rows = map {chomp; $_} (); print Dumper in_three_chunks(\@rows, 20); sub in_three_chunks { my $rows = shift; my $criteria = shift; return unless ref $rows or not $criteria =~ /^\d+$/; my %parted = ( before => [], matching => [], after => [] ); for my $row (@$rows) { my $cur = [split /;/, $row]; push @{$parted{'matching'}}, $cur and next if $cur->[2] == $criteria; unless (@{$parted{'matching'}}) { push @{$parted{'before'}}, $cur; } else { push @{$parted{'after'}}, $cur; } } return \%parted; } __DATA__ Zeile1;;100;; Zeile2;;60;; Zeile3;;20;; Zeile4;;20;; Zeile5;;40;;